X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL,BAYES_00,SPF_NEUTRAL,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4CCB4025.6070405@cornell.edu> Date: Fri, 29 Oct 2010 17:44:05 -0400 From: Ken Brown User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101013 Thunderbird/3.1.5 MIME-Version: 1.0 To: cygwin Subject: localtime and TZ Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com While trying to debug a timezone problem in the Cygwin build of emacs, I've come across a difference between Cygwin and Linux in the behavior of localtime with respect to TZ. Suppose I set TZ, call localtime, unset TZ, and call localtime again. On Cygwin, the second call to localtime re-uses the previous value of TZ. On Linux, localtime reverts to giving local information, just as if TZ had never been set. Here's a Simple Test Case: #include #include extern char **environ; void unset_TZ (void) { char **from, **to; for (to = from = environ; (*to = *from); from++) if (! (to[0][0] == 'T' && to[0][1] == 'Z' && to[0][2] == '=')) to++; } 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); unset_TZ (); printf ("TZ unset; hour = %d\n", localtime (&now)->tm_hour); putenv ("TZ=PST8"); printf ("TZ=PST8; hour = %d\n", localtime (&now)->tm_hour); unset_TZ (); printf ("TZ unset again; hour = %d\n", localtime (&now)->tm_hour); } I run the program with TZ unset. The output on Cygwin is TZ is initially unset; hour = 17 TZ=GMT0; hour = 21 TZ unset; hour = 21 TZ=PST8; hour = 13 TZ unset again; hour = 13 The output on Linux is TZ is initially unset; hour = 17 TZ=GMT0; hour = 21 TZ unset; hour = 17 TZ=PST8; hour = 13 TZ unset again; hour = 17 Is this a bug in Cygwin, or is the difference with Linux by design? Ken -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple