[R] system time is 5 hours off in Windows

Setzer.Woodrow@epamail.epa.gov Setzer.Woodrow at epamail.epa.gov
Tue Jan 23 16:09:42 CET 2001


I think I understand what is happening with my system time problem (though
not why, exactly).  The problem is not in R, but, apparently, in an
interaction between my version of msvcrt.dll (version 6.10.8637.0) and the
implementations of the POSIX time functions in mingw32.  At the end of this
message is a little c program and batch file that demonstrate the problem.

This is the result of a run on my machine:

A:\>ttime

A:\>echo off
TZ=
tzname[0] tzname[1]
Before tzset():  PST PDT
After tzset():   Eastern Standard Time Eastern Daylight Time
Tue Jan 23 09:51:42 2001
TZ=Eastern Standard Time
tzname[0] tzname[1]
Before tzset():  PST PDT
After tzset():   Eas ter
Tue Jan 23 14:51:42 2001
TZ=EST+5
tzname[0] tzname[1]
Before tzset():  PST PDT
After tzset():   EST
Tue Jan 23 09:51:43 2001
A:\>


So, initially, TZ is not set, the value of tzname defaults to PST PDT (home
time zone of Redmond!), and after calling tzset(), tzname has reasonable
sounding values (though not exactly POSIXly correct).  The functions time()
and ctime() report the correct value.

Set TZ to the value of tzname[0], and now, after calling tzset(), tzname[0]
is "Eas" and tzname[1] is "ter", and the time reported is local time plus 5
hours (UTC time?).  If I set TZ to a value sanctioned by the libc
documentation for the POSIX time functions, tzname[0] is reasonable, and
again I get the correct time.

The problem seems to be that setting TZ to a value returned by tzname is
not guaranteed to result in a correct conversion to local time, at least
with my setup.  I've tried this on two pcs running Win95, and in all cases
the correct time is returned.  From Dr. Ripley's comment about a lack of
bug reports about this, I'd have to conclude that most Win98 versions work
as well
-----------------------------

testtime.c:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>

int main(void)
{
  time_t t;
  printf("tzname[0] tzname[1]\n");
  printf("Before tzset():  %s %s\n",tzname[0],tzname[1]);
  tzset();
  printf("After tzset():   %s %s\n",tzname[0],tzname[1]);
  time(&t);
  printf("%s",ctime(&t));
  return(0);
}

ttime.bat:

echo off
set TZ=
echo TZ=%TZ%
testtime.exe
set TZ=Eastern Standard Time
echo TZ=%TZ%
testtime.exe
set TZ=EST+5
echo TZ=%TZ%
testtime.exe

R. Woodrow Setzer, Jr.                                            Phone:
(919) 541-0128
Experimental Toxicology Division                       Fax:  (919) 541-5394
Pharmacokinetics Branch
NHEERL MD-74; US EPA; RTP, NC 27711

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list