This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

localtime and TZ


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 <time.h>
#include <stdio.h>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]