Hi All,
I have been really struggling with date and times in LUA. Im from a sql / c# background where you can easily do things like date1 - date2, etc, etc
I’ve been searching for ages trying to find an easy was to compare two date from strings. I have stored dates in UTC format which I want to compare to the local device time (in UTC).
I came across this module which seems to be perfect but no one has really mentioned it on any of the posts about handling date and times. Im wondering if anybody has looked in to it and can tell me if there is a reason no one is using it?
http://files.luaforge.net/releases/date/date
I have been playing around with it and so far im really impressed. for example:
local date = require("date") local now = date():toutc() -- gets device time in UTC local lastUpd = date("2014-07-09T04:15:29.470Z") -- my date string stored as UTC locally i.e. last update time print ("secs since updated:", (now - lastUpd):spanseconds()) print ("mins since updated:", (now - lastUpd):spanminutes()) print ("hours since updated:", (now - lastUpd):spanhours())
gives me the following outut:
NOW: Wed Jul 09 2014 23:51:05 LASTUPD: Wed Jul 09 2014 04:15:29.47 secs since updated: 70535.53 mins since updated: 1175.5921666667 hours since updated: 19.593202777778
There are a whole host of other method which will be very very useful, for example:
add days, min, secs, etc to a date
get the min, secs, etc from a date
compare dates < > = , etc
add dates together…
It would be great if somebody with a very in depth knowledge of LUA / corona could look in to this and see if it a viable module. I think so many people would find it useful…
*** I have not looked in to if this handles daylight savings ***
Thanks
Dave