Message-Id: <200004120924.FAA07789@delorie.com> From: "Larry Olin Horn" Organization: Millsaps College - Comp and Telecom To: djgpp AT delorie DOT com Date: Wed, 12 Apr 2000 05:24:13 -0500 Subject: Re: timezone problems: tm_isdst not set; strftime("%z") is -0000 References: <200004111359 DOT JAA06219 AT delorie DOT com> In-Reply-To: X-mailer: Pegasus Mail for Win32 (v3.12c) Reply-To: djgpp AT delorie DOT com > I cannot reproduce the first problem. Please always make a point of Transcript with output and source code at end of this message. Basically, the tm struct info says it's Standard Time (tm_isdst == 0) when it should be Daylight Time. If it *were* CST instead of CST, then the __tm_zone and __tm_gmtoff would be correct, and the "%Z" format would be correct also. However, it looks like the "%z" format is not looking at __tm_gmtoff to derive the correct "+/-hhmm" text. > Is the value of the TZ environment variable set in DJGPP.ENV or in the > environment? Environment. > In any case, %z is a non-ANSI format, and it isn't even documented in > the DJGPP library reference. So I wonder how did you come about using > it. It's documented at , although I actually found it in the strftime man page on RH Linux 6.1. The fact that DJGPP displays "-0000" indicates at least it's known by the code, just not using the correct offset. > > %a, %d %b %Y %H:%M:%S %Z --> Tue, 11 Apr 2000 09:50:47 CST > > I don't see any problem with this behavior. If you think there is a > problem, please explain what it is. Wrong time zone (CST instead of CDT), although it's technically correct based on the tm values. I just displayed this to contrast the "%Z" and "%z" results, where "%z" is wrong in both respects. > Here's the test program I used: And the transcript of my test (xrun.bat), source at end: ----- xrun.bat ----- set DJGPP=c:/djgpp/djgpp.env set PATH=c:\djgpp\bin;%PATH% echo %TZ% gcc -v gcc x.c -o x.exe x type x.c exit ----- C:\wrk\cwrk> xrun C:\wrk\cwrk> set DJGPP=c:/djgpp/djgpp.env C:\wrk\cwrk> set PATH=c:\djgpp\bin;%PATH% C:\wrk\cwrk> echo %TZ% CST6CDT C:\wrk\cwrk> gcc -v Reading specs from c:/djgpp/lib/gcc-lib/djgpp/2.952/specs gcc version 2.95.2 19991024 (release) C:\wrk\cwrk> gcc x.c -o x.exe C:\wrk\cwrk> x Dumping tm_ptr: tm_sec = 36 tm_min = 21 tm_hour = 4 tm_mday = 12 tm_mon = 3 tm_year = 100 tm_wday = 3 tm_yday = 102 tm_isdst = 0 (** should be 1 **) __tm_zone = CST (** should be CDT **) __tm_gmtoff = -21600 (** should be -18000 **) Dumping tzname: tzname[0] = CST tzname[1] = CDT asctime = Wed Apr 12 04:21:36 2000 strftime: %a, %d %b %Y %H:%M:%S %z --> Wed, 12 Apr 2000 04:21:36 -0000 (** should be -0500 **) %a, %d %b %Y %H:%M:%S %Z --> Wed, 12 Apr 2000 04:21:36 CST (** should be CDT **) C:\wrk\cwrk> type x.c #include #include #include #define FMT1 "%a, %d %b %Y %H:%M:%S %z" #define FMT2 "%a, %d %b %Y %H:%M:%S %Z" main( int argc, char *argv[] ) { struct tm *tm_ptr; time_t tval; char ltime[100]; char rtime1[100]; char rtime2[100]; tzset(); time( &tval ); tm_ptr = localtime( &tval ); strncpy( ltime, asctime( tm_ptr ), 99 ); strftime( rtime1, 99, FMT1, tm_ptr ); strftime( rtime2, 99, FMT2, tm_ptr ); printf( "\n" ); printf( "Dumping tm_ptr:\n" ); printf( " tm_sec = %d\n", tm_ptr->tm_sec ); printf( " tm_min = %d\n", tm_ptr->tm_min ); printf( " tm_hour = %d\n", tm_ptr->tm_hour ); printf( " tm_mday = %d\n", tm_ptr->tm_mday ); printf( " tm_mon = %d\n", tm_ptr->tm_mon ); printf( " tm_year = %d\n", tm_ptr->tm_year ); printf( " tm_wday = %d\n", tm_ptr->tm_wday ); printf( " tm_yday = %d\n", tm_ptr->tm_yday ); printf( " tm_isdst = %d (** should be 1 **)\n", tm_ptr->tm_isdst ); printf( " __tm_zone = %s (** should be CDT **)\n", tm_ptr->__tm_zone ); printf( " __tm_gmtoff = %d (** should be -18000 **)\n", tm_ptr->__tm_gmtoff ); printf( "\n" ); printf( "Dumping tzname:\n" ); printf( " tzname[0] = %s\n", tzname[0] ); printf( " tzname[1] = %s\n", tzname[1] ); printf( "\n" ); printf( "asctime = %s\n", ltime ); printf( "\n" ); printf( "strftime:\n" ); printf( " %s --> %s\n(** should be -0500 **)\n", FMT1, rtime1 ); printf( " %s --> %s\n(** should be CDT **)\n", FMT2, rtime2 ); printf( "\n" ); } C:\wrk\cwrk> exit --