localtime and TZ
Eric Blake
eblake@redhat.com
Fri Oct 29 22:31:00 GMT 2010
On 10/29/2010 04:11 PM, Ken Brown wrote:
>
> Thanks, Eric. I didn't know about any of this. (I was using a modification of a configure test from the emacs sources.)
Probably worth pointing it out to the emacs upstream, then :)
> But I get the same behavior with the following revised test case:
>
> #include <time.h>
> #include <stdio.h>
>
> int
> main (void)
> {
> time_t now = time ((time_t *) 0);
> printf ("TZ is initially unset; hour = %d\n", localtime (&now)->tm_hour);
> putenv ("TZ=GMT0");
> printf ("TZ=GMT0; hour = %d\n", localtime (&now)->tm_hour);
> unsetenv("TZ");
> printf ("TZ unset; hour = %d\n", localtime (&now)->tm_hour);
> putenv ("TZ=PST8");
> printf ("TZ=PST8; hour = %d\n", localtime (&now)->tm_hour);
> unsetenv("TZ");
> printf ("TZ unset again; hour = %d\n", localtime (&now)->tm_hour);
> }
>
> So the question remains whether this difference between Cygwin and Linux is a bug or by design.
Apparently by design. POSIX requires:
http://www.opengroup.org/onlinepubs/9699919799/functions/localtime.html
Local timezone information is used as though localtime() calls tzset().
http://www.opengroup.org/onlinepubs/9699919799/functions/tzset.html
The tzset() function shall use the value of the environment variable TZ
to set time conversion information used by ctime , localtime , mktime ,
and strftime . If TZ is absent from the environment,
implementation-defined default timezone information shall be used.
But not the best of design, so a patch to fix cygwin to copy Linux'
behavior is probably appreciated.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20101029/26c9d194/attachment.sig>
More information about the Cygwin
mailing list