[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: os.time() and timezones
- From: Daurnimator <quae@...>
- Date: Sat, 14 Apr 2012 13:56:43 +1000
On 14 April 2012 06:26, Sean Conner <sean@conman.org> wrote:
> Even operating systems have trouble with timezones:
>
> http://www.chronos-st.org/Discovering%20the%20Local%20Time%20Zone--Why%20It%27s%20a%20Hard%20Problem.html
>
>> I use this kind of logic to find the timezone offset in pl.Date:
>>
>> local t = os.time()
>> local ut = os.date('!*t',t)
>> local lt = os.date('*t',t)
>> thour = lt.hour - ut.hour
>> tmin = lt.min - ut.min
>>
>> If this is misguided I would certainly like to know!
>
> It is. Try this:
>
> gmt = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ,
> 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 }
> loc = { 19 , 20 , 21 , 22 , 23 , 0 , 1 , 2 , 3 , 4 , 5 , 6 ,
> 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 }
>
> for i = 1 , 24 do
> print(i,loc[i] - gmt[i])
> end
>
> And even when it does work, it still doesn't take into account DST. I found
> this works:
>
> now = os.time()
> lmt = os.date("*t",now)
> gmt = os.date("!*t",now)
> timel = os.time(lmt)
> timeg = os.time(gmt)
> zone = os.difftime(timel,timeg)
>
> if lmt.isdst then
> if zone < 0 then
> zone = zone + 3600
> else
> zone = zone - 3600
> end
> end
>
> -spc (Time is hard! I wonder how The Doctor does it?)
>
>
And now you're assuming daylight savings is for an hour.
Also that timezones are only on the hour.
eg; see Lord Howe island in Australia: LHDT/LHST