I noticed a couple of bizarre readings in my logs and have dug up an observation about date().
I need to execute a few checks every minute, on the minute. I was posting the time every time I did this and noticed it would sometimes say that the time was sometimes hour:(min-1):59 rather than hour:min:0
checking through the code I saw I was calling date() twice, the first time with no argument and the 2nd with the argument time(). I would have expected them to return the same values,or at the very least for the 2nd call to return a time that occurs AFTER the 1st. However, intermittently it returns a time BEFORE the first call.
This is some simple AGENT test code to demonstrate:
function timer_test(){ imp.wakeup(1,timer_test); local t1=date(); local t2=date(time()); if (t2.sec!=t1.sec) server.log("ERROR: t1="+http.jsonencode(t1)+" t2="+http.jsonencode(t2)); } timer_test();
I only had to wait about 2 hours for a bundle of messages in the device log to turn up.
One might expect t2.time to be occasionally larger than t1.time, but not the other way round.
I haven’t tried it in the device yet.
Also interesting to note the undocumented date().usec field. Is this usable?