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 #59 received at 11281 <at> debbugs.gnu.org (full text, mbox):

From: Kazuhiro Ito <kzhr <at> d1.dion.ne.jp>
To: Eli Zaretskii <eliz <at> gnu.org>
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 21:03:43 +0900
[Message part 1 (text/plain, inline)]
> > ;; After setting timezone without DST in the Windows Control Panel
> > $ TZ= emacs -Q
> > 
> > (let ((time (encode-time '(0 0 12 20 5 2025 nil nil t))))
> >   (setenv "TZ" "JST-9")
> >   (decode-time time "est5edt"))
> > 
> > -> unexpected result
> > 
> > So, following code would fail too.
> > 
> > (let ((time (encode-time '(0 0 12 20 5 2025 nil nil t))))
> >   ;; After setting timezone without DST in the Windows Control Panel
> >   (setenv "TZ" nil)
> >   (setenv "TZ" "JST-9")
> >   (decode-time time "est5edt"))
> > 
> > -> unexpected result
> > 
> > > That is, as long as you tell MSVCRT that
> > > your current timezone doesn't use DST, the conversion is correct.
> > 
> > As I wrote above, this problem occurs after you once call `(setenv
> > "TZ" nil)' under setting that system timezone is non-DST
> > timezone.  If you don't set TZ to nil, conversion would always
> > succeed.
> > 
> > $ TZ=est5edt emacs -Q
> > 
> > (let ((time (encode-time '(0 0 12 20 5 2025 nil nil t))))
> >   (setenv "TZ" "JST-9t")
> >   (decode-time time "est5edt"))
> > 
> > -> expected result
> > 
> > (let ((time (encode-time '(0 0 12 20 5 2025 nil nil t))))
> >   (setenv "TZ" "pst8pdt")
> >   (decode-time time "est5edt"))
> > 
> > -> expected result
> 
> 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
>
> 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.  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.

There may be another issue about timezones where DST shift is not one
hour.  Wikipedia says the Lord Howe Island is so.  However I apologize
for overlooking Emacs on Windows users live there.

Tiny patch is attached.

-- 
Kazuhiro Ito
[0001-Adjust-_dstbias-value-after-tzset-on-Windows.patch (text/plain, attachment)]

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.