! Time utils

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

! Time utils

Post by Dutchman » Wed Nov 20, 2019 12:39 pm

! Time utils {/Extensions/Misc/! Time utils}
Contains some time conversion functions.

Code: Select all

' {/Extensions/Misc/! Time utils}
[ time functions ]
'
[–––––––––––––––––––––––– Functions ––––––––––––––––––––––––
Time0$(AMPM,short)
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
–––
Time1$(seconds,width)
returns time string with hours, minutes, seconds
in format h:mm'ss"
width determines minimum width of string
width has only effect if >10
–––
End of function description –––––––––––]
'
[–––––––––––––––––––––– Implementation ––––––––––––––––––––––]
DEF Time0$(AMPM,short)
hh,mm,ss = NOW|3
IF AMPM
  IF hh>=12 
    AP$="PM" :hh-=12
  ELSE: AP$="AM"
  ENDIF
  ELSE: AP$=""
ENDIF
t$=STRTEXT(hh "?0:")+STRTEXT(mm "00")
IF short THEN t$+="'"+STRTEXT(ss "00""")
RETURN t$+AP$
END DEF

DEF Time1$(seconds,width)
IF width>10 THEN F$=STRREP "?",width-10 ELSE F$=""
hours=INT(seconds/3600)
mins=INT((seconds-hours*3600)/60)
secs=seconds-hours*3600-mins*60
T$=STRTEXT(hours f$+"0:")+STRTEXT(mins "00'")+STRTEXT(secs "00""")
RETURN t$
END DEF
# Time functions.bb is a test and demo program
It is still a long way to go

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

Re: ! Time utils

Post by kibernetik » Wed Nov 20, 2019 2:40 pm

Why not to merge a code topic with an example/test topic into a single topic?
After some time when there will be many library functions in the section then the code topic and its test topic can become separated...
Also it may become difficult to find a corresponding example topic or even to know that it exists, because Forum topics are sorted by last modification time.

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

Re: ! Time utils

Post by Dutchman » Wed Nov 20, 2019 7:06 pm

kibernetik wrote:
Wed Nov 20, 2019 2:40 pm
Why not to merge a code topic with an example/test topic into a single topic?
After some time when there will be many library functions in the section then the code topic and its test topic can become separated...
Also it may become difficult to find a corresponding example topic or even to know that it exists, because Forum topics are sorted by last modification time.
I want to keep the libraries "! etc" separate from the test and demo programs "# etc".
The libraries will generally contain multiple functions, for example the "! DSP utils" will be greatly extended.
The test programs will always mainly relate to the added functions.
I will explain these added functions with their test program in the doc "About ...".
I have already extended the doc in that sense eg for "FIRgain".
It is still a long way to go

Post Reply