lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Diego - Red Baires wrote:
Hi guys, i still cannot apply the concept that Kein recommends.
Pls analize this results:
      ^^^^^^^
analyze

----------
myHour = os.time( { year="2008", month="01", day="01", hour="00", min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)

myHour = os.time( { year="2009", month="01", day="00", hour="00", min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)
----------
output: 1199152800 - 7200
1230688800 - 7200

Heh, there is no day 00 :-)

The 7200 is the difference in time zone versus UTC, because the Unix epoch is 00:00:00 UTC on January 1, 1970. Looks like Spain.

What are you doing with fmod? You can use myHour % 86400.

But why are you using fmod? Is your date a local date or a UTC date? If it's local date, you count your hours with respect to your midnight reference of the same day. I've already shown that. If your application is international, then you also need to take into consideration your time zone.

it continues to return "7200" if i change the year (it is what we expect) but it returns
different values to different months values. see this

----------
myHour = os.time( { year="2008", month="01", day="01", hour="00", min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)

myHour = os.time( { year="2009", month="07", day="00", hour="00", min="00" })
ts = math.fmod(myHour, 86400)
print (myHour .." - ".. ts)
----------
output: 199152800 - 7200
1246330800 - 10800

The only thing I can think of that changes it would be Daylight Savings Time (DST). On my machine, there is no difference in the ts result, meaning that on both dates, the times have the same hour difference with respect to UTC.

is it because of the locale ? do you have any example to set UTC locale ? (i coudnt find an example)

If you have DST, and you specify dates in local time, then the calculations will be more complex. I'll leave the implementation to you. :-)

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia