Bug in time NOW|3

Post Reply
User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Bug in time NOW|3

Post by Dutchman » Sat Sep 07, 2019 3:00 pm

I made code for display of time in 12 hours or 24 hours mode.
At about 16:50 I got strange results and finally decided to run it periodically:

Code: Select all

DO
PRINT "Time is "+Time0$(0)+" or "+Time0$(1)
delay 1.1
REDO
END

'========= Time functions ========
DEF Time0$(AMPM)
'Returns current time string in format hh:mm'ss"
'If AMPM=1 then 12 hours display with AM or PM is used
'else return string is 24 hours display
hh,mm,ss = NOW|3
IF AMPM
  IF hh>=12 
    AP$=" PM" :hh-=12
  ELSE: AP$=" AM"
  ENDIF
  ELSE: AP$=""
ENDIF
RETURN STRTEXT hh "?0:"+STRTEXT mm "00'"+STRTEXT ss "00"""+AP$
END DEF
and got the following results:
Wrong time display.JPG
Wrong time display.JPG (71.58 KiB) Viewed 571 times
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Bug in time NOW|3

Post by kibernetik » Sat Sep 07, 2019 5:40 pm

Thank you very much for report!
I will check.

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Bug in time NOW|3

Post by kibernetik » Sat Sep 07, 2019 5:56 pm

There are 2 ways to submit parameters to a function:
- to put its arguments inside brackets, so the function exactly knows what its arguments are;
- to leave function arguments without brackets, then functions consideres EVERYTHING after the function name being its arguments.

So, if you have some expression then you have to consider this. If not everything after the function name are its own arguments then you need to limit its arguments using brackets.

If a function cannot have any arguments (for example RND) then there is no need in empty brackets after the function, because function anyway does not expect any arguments.

So, your code could look like:

Code: Select all

DO
PRINT "Time is "+Time0$(0)+" or "+Time0$(1)
delay 1.1
REDO
END

'========= Time functions ========
DEF Time0$(AMPM)
'Returns current time string in format hh:mm'ss"
'If AMPM=1 then 12 hours display with AM or PM is used
'else return string is 24 hours display
hh,mm,ss = NOW|3
IF AMPM
  IF hh>=12 
    AP$=" PM" :hh-=12
  ELSE: AP$=" AM"
  ENDIF
  ELSE: AP$=""
ENDIF
RETURN (STRTEXT hh "?0:")+(STRTEXT mm "00'")+(STRTEXT ss "00""")+AP$
END DEF
or:

Code: Select all

DO
PRINT "Time is "+Time0$(0)+" or "+Time0$(1)
delay 1.1
REDO
END

'========= Time functions ========
DEF Time0$(AMPM)
'Returns current time string in format hh:mm'ss"
'If AMPM=1 then 12 hours display with AM or PM is used
'else return string is 24 hours display
hh,mm,ss = NOW|3
IF AMPM
  IF hh>=12 
    AP$=" PM" :hh-=12
  ELSE: AP$=" AM"
  ENDIF
  ELSE: AP$=""
ENDIF
RETURN STRTEXT(hh "?0:")+STRTEXT(mm "00'")+STRTEXT(ss "00""")+AP$
END DEF
otherwise you just get a very strange format string for your very first function call

Code: Select all

STRTEXT hh "?0:"
and you got no errors because all parts of this sum are valid text values.

User avatar
Dutchman
Posts: 151
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: Bug in time NOW|3

Post by Dutchman » Sun Sep 08, 2019 8:59 am

OK, that's very clear. thanks.
But it is also very understandable that I made this mistake after all the examples in which you can omit brackets and commas. 8-)
 Maybe you should give such an error example in the manual :?:
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 142
Joined: Tue Aug 06, 2019 3:03 pm

Re: Bug in time NOW|3

Post by kibernetik » Mon Sep 09, 2019 12:58 am

Dutchman wrote:
Sun Sep 08, 2019 8:59 am
OK, that's very clear. thanks.
But it is also very understandable that I made this mistake after all the examples in which you can omit brackets and commas. 8-)
 Maybe you should give such an error example in the manual :?:
Yes, this topic is covered in the documentstion. Please look at "Code writing" section, pages 5-6.

Post Reply