help-gnats
[Top][All Lists]
Advanced

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

Re: gnats devel FW: New time zones


From: Carl E . Lindberg
Subject: Re: gnats devel FW: New time zones
Date: Thu, 24 May 2001 17:05:43 -0400


>I typically build-my-own %z equivalent out of using the same reference
>time and passing it to both localtime() and gmtime() converting back
>to seconds

Yup, that's the basic approach. I've found though that it's problematic to use mktime() to convert back to seconds, as some of the sytems that have the tm_gmtoff field use it inside mktime(), so the two conversions would end up at the same seconds value. My code just

> and then doing the subtraction to get the offset in seconds
>and dividing by 36 to get 'hours' in hundreds.

Careful -- many localities are offset X-hours-and-a-half from UTC, and in those cases the offsets should be like +0430 (dividing by 36 would get you +0450). You need to split out the hours and minutes values to do it right.

[There's even a couple of places that are 45 minutes offset -- Nepal and an island somewhere near New Zealand I think.]


>For what it is worth, the %z format was introduced to FreeBSD 4.0 in
>that lib/libc/stdtime/strftime.c in version 1.25 of the file which was
>in FreeBSD 4.0 and subsequent releases contains the patch to support it.

        Cool, that's good to know.

>My recommendation would be to use a configure test for the %z format
>and then use strftime() if it works or use a compatibility package if
>it does not.

Probably the best idea. I'm sure my code would work the same even on those platforms, but it's better to use the system-provided implementations if at all possible.

        -Carl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]