delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/10/29/18:16:18

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD
X-Spam-Check-By: sourceware.org
Message-ID: <4CCB47A6.9010600@redhat.com>
Date: Fri, 29 Oct 2010 16:16:06 -0600
From: Eric Blake <eblake AT redhat DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.4
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: localtime and TZ
References: <4CCB4025 DOT 6070405 AT cornell DOT edu> <4CCB42AF DOT 2090907 AT redhat DOT com> <4CCB439B DOT 7060602 AT redhat DOT com> <4CCB4676 DOT 8080609 AT cornell DOT edu>
In-Reply-To: <4CCB4676.8080609@cornell.edu>
OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------enigFB43C151F331E752B3EA2710
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On 10/29/2010 04:11 PM, Ken Brown wrote:
>=20
> Thanks, Eric.  I didn't know about any of this.  (I was using a modificat=
ion 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:
>=20
> #include <time.h>
> #include <stdio.h>
>=20
> int
> main (void)
> {
>   time_t now =3D time ((time_t *) 0);
>   printf ("TZ is initially unset; hour =3D %d\n", localtime (&now)->tm_ho=
ur);
>   putenv ("TZ=3DGMT0");
>   printf ("TZ=3DGMT0; hour =3D %d\n", localtime (&now)->tm_hour);
>   unsetenv("TZ");
>   printf ("TZ unset; hour =3D %d\n", localtime (&now)->tm_hour);
>   putenv ("TZ=3DPST8");
>   printf ("TZ=3DPST8; hour =3D %d\n", localtime (&now)->tm_hour);
>   unsetenv("TZ");
>   printf ("TZ unset again; hour =3D %d\n", localtime (&now)->tm_hour);
> }
>=20
> 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.

--=20
Eric Blake   eblake AT redhat DOT com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org


--------------enigFB43C151F331E752B3EA2710
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBCAAGBQJMy0emAAoJEKeha0olJ0NqOHIIAK/ZzSQEyeAxeIr3xqw8D+0q
NxoCDOiyXIq+QdkjF2pMmavHL9mJE+r/aGsV0DV7Supikza4t4QtFWAaD4cWI3E0
7v1U5eOznALkuMtUly7I91CfzhRf4vsxjvTDCsQUsvYzXJ1TnssxuN6KdUDzbRAT
4uS8o/ltBcmT2fQyrXkgSFv20RKTWlFfHZWAVR2WT1RmItoqQuiIah+I6m6DLmF6
QHgEg8LDMs4HA9f+ZxjQhei6NKlNvOSFYC7hK06ZswxCrI2X/U/bTwN5fTUE3HBP
o8dYKeI5aabvfrc+imrUgF+9j1YjBCJtimPFVL36q474XmR7o2ffi+V9At8Urb4=
=bX3p
-----END PGP SIGNATURE-----

--------------enigFB43C151F331E752B3EA2710--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019