## DatedTics function

Dutchman
Posts: 913
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: ### DatedTics function

I needed an utility to provide a file or filename with a date-time stamp with second-precision.
Of course you can use hours, minutes and seconds, but a decimal comparison with the current date then requires conversion.
That is why I have chosen the number of seconds that have elapsed during the day.
The difference in seconds is then easily calculated.
In order to be able to give the number of 'Tics' a decimal number per day, I have added a parameter 'gain' with which the length of a 'Tic' can be changed. The separation between the ISO date string and the Tics is the other parameter:

DatedTics \$ (separator \$, gain)
• Returns ISO date extended with number of seconds with separator \$ and multiplied with gain
• The number of digits can be set with the local constant F \$ containing zeros.

Code: Select all

``````'DatedTics.function with testprogram
'by Dutchman, November 2018
FOR n=1 TO 2
IF n=2 THEN Tic= 1E5/(24*3600) ELSE Tic=1
Out\$=DatedTics\$("#",Tic)
PRINT "'DatedTics\$'="""&Out\$&""" if Tic="&Tic&" sec."
PRINT ,"maximum Tics-value="& (DatedTics\$.MaxValue-1)
NEXT n
END

DEF DatedTics\$(separator\$,gain) ' function by Dutchman
'Returns ISO-date extended with
'  number of seconds in the day
'and separated with 'separator\$'
'and multiplied with gain
'Maximum result should fit in:
F\$="00000" ' outputstring with zeros
'--- check range
MaxDigits=LEN(F\$) 'maximum number of digits
IF gain=0 THEN gain=1
Maxvalue=24*3600*gain
IF MaxValue>10^maxdigits THEN Error
'--- ISO-date
Date\$=STR\$(CURRENT_YEAR()*10000+100*CURRENT_MONTH()+CURRENT_DATE(),"########")
'--- Tic\$
Tics=CURRENT_HOUR()*3600+CURRENT_MINUTE()*60+CURRENT_SECOND()
Tics*=gain
Tics\$=RIGHT\$(F\$&STR\$(Tics,"#"),maxdigits)
RETURN Date\$&Separator\$&Tics\$
Error:
TEXT ! TEXT CLEAR
PRINT "Gain is too large in function 'DatedTics\$'."
STOP
END DEF ' DatedTics
`````` Output from test.JPG (28.28 KiB) Viewed 999 times
We consider it a refreshing mental exercise to figure out ways to circumvent foolishness (Quote from Richard)