GNU bug report logs - #11281
DST has not effect on windows XP when system DST adjustment is disabled

Previous Next

Package: emacs;

Reported by: Shuguang Sun <shuguang <at> gmail.com>

Date: Thu, 19 Apr 2012 16:46:01 UTC

Severity: minor

Done: Stefan Kangas <stefan <at> marxist.se>

Full log


Message #62 received at 11281 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kazuhiro Ito <kzhr <at> d1.dion.ne.jp>
Cc: 11281 <at> debbugs.gnu.org, stefankangas <at> gmail.com
Subject: Re: bug#11281: DST has not effect on windows XP when system DST
 adjustment is disabled
Date: Sun, 25 May 2025 16:13:26 +0300
> Date: Sun, 25 May 2025 21:03:43 +0900
> From: Kazuhiro Ito <kzhr <at> d1.dion.ne.jp>
> Cc: 11281 <at> debbugs.gnu.org, stefankangas <at> gmail.com
> 
> > Thanks.  Volunteers are welcome to investigate how MSVCRT works and
> > why this sometimes causes incorrect results, because I've exhausted my
> > knowledge of this dark corner.
> 
> I've found the fix.
> I wrote tiny test program.
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
> 
> static void show_globals () {
>   printf("_daylight = %d\n" , _daylight );
>   printf("_timezone = %ld\n", _timezone );
>   printf("_tzname[0] = %s\n", _tzname[0]);
>   printf("_dstbias = %d\n\n", _dstbias );
> }
> 
> int main(void) {
>   putenv("TZ=JST-9");
>   _tzset();
>   printf("JST-9\n");
>   show_globals();
> 
>   putenv("TZ=est5edt");
>   _tzset();
>   printf("est5edt\n");
>   show_globals();
> 
>   putenv("TZ=");
>   _tzset();
>   printf("System timezone\n");
>   show_globals();
> 
>   putenv("TZ=est5edt");
>   _tzset();
>   printf("est5edt (2nd)\n");
>   show_globals();
> 
>   return 0;
> }
> 
> 
> Result is here.
> 
> > JST-9
> > _daylight = 0
> > _timezone = -32400
> > _tzname[0] = JST
> > _dstbias = -3600

Isn't this result strange?  If a timezone has no DST, why is _dstbias
not zero?

> > est5edt
> > _daylight = 101
> > _timezone = 18000
> > _tzname[0] = est
> > _dstbias = -3600
> >
> > System timezone
> > _daylight = 0
> > _timezone = -32400
> > _tzname[0] = 東京 (標準時)
> > _dstbias = 0
> >
> > est5edt (2nd)
> > _daylight = 101
> > _timezone = 18000
> > _tzname[0] = est
> > _dstbias = 0
> 
> When I set timezone to system timezone without DST, _dstbias global
> variable is set to 0.

That's not what I see for JST-9 above.  I compiled the program here,
and I see the same result on my system for JST-9: _daylight is zero,
but _dstbias is -3600.  If I use JST-9JD, I get this:

  JST-9JDT
  _daylight = 74
  _timezone = -32400
  _tzname[0] = JST
  _dstbias = -3600

which is more reasonable.

> But its value is never changed by setting timezone with TZ
> environmental variable and affects calculation UTC offset of DST.
> To change _dstbias value to -3600 fixes the issue.

Sorry, I don't think I understand: AFAIU, _dstbias can legitimately be
zero in timezones that don't support DST.  If that is true, correcting
a zero-valued _dstbias to 1 hour will cause problems, no?  Maybe we
should also look at the value of _daylight, and only do the _dstbias
correction of _daylight is zero (i.e. no DST in this timezone)?  Or
what am I missing?

> Tiny patch is attached.

Thanks.  In any case, we should redirect tzset to a Windows specific
version in w32.c, and do the correction there, instead of in
timefns.c.  In addition, mingw.org's MinGW needs to declare _dstbias
(it doesn't have the declaration in time.h).  I will do all these, but
let's first understand what these changes do and why they fix the
problem, and also how to apply them correctly without adversely
affecting timezones without DST.




This bug report was last modified 17 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.