countdown display code
- Posted by Senator Aug 16, 2020
- 1660 views
The following code displays a countdown intended to update every second. Most often the seconds display a decrement of 2 seconds, sometimes a 1 second decrement is displayed.
Is there an error in my code?
-- -- count_down.ex -- include std/datetime.e include std/math.e include std/graphics.e include std/os.e function DaysBetweenDates(datetime dt1,datetime dt2) atom d,h,m,s=diff(dt1,dt2) d=s/86400 h=frac(d)*24 -- hours.xxx d=trunc(d) -- days m=frac(h)*60 -- minutes.xxx h=trunc(h) -- hours s=frac(m)*60 -- seconds.xxx m=trunc(m) -- minutes s=trunc(s) -- seconds return {d,h,m,s} end function public procedure now_until(datetime dt2={2020,9,1,0,0,0}) sequence bal, pos = get_position() loop do text_color(BRIGHT_WHITE) position(pos[1],pos[2]) puts(1," ") position(pos[1],pos[2]) text_color(BLUE) bal=DaysBetweenDates(now(),dt2) printf(1,"%d-%d:%d:%d",{bal[1],bal[2],bal[3],bal[4]}) sleep(1) until equal(bal,dt2) end loop end procedure now_until()
Thanks, Ken