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 #77 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: Mon, 26 May 2025 23:50:51 +0900
> I think I see the problem: when TZ is defined in the environment,
> tzset updates _daylight, but doesn't touch _dstbias.  So if you start
> from a timezone without DST and then switch to a timezone with DST,
> _dstbias stays zero, and local time is computed incorrectly.
> 
> Therefore, I suggest the patches below.  Could you please try them?

As far as I tested, the issue is resolved.
Thank you!

> diff --git a/src/w32.c b/src/w32.c
> index 5de721a..a98a008 100644
> --- a/src/w32.c
> +++ b/src/w32.c
> @@ -10289,6 +10289,30 @@ w32_read_registry (HKEY rootkey, Lisp_Object lkey, Lisp_Object lname)
>  }
>  
>  
> +/* mingw.org's MinGW doesn't declare _dstbias.  MinGW64 defines it as a
> +   macro.  */
> +#ifndef _dstbias
> +__MINGW_IMPORT int _dstbias;
> +#endif
> +
> +/* Fix a bug in MS implementation of 'tzset', to be called immediately
> +   after 'tzset'.  */
> +void
> +w32_fix_tzset (void)
> +{
> +  char *tz_env = getenv ("TZ");
> +
> +  /* When TZ is defined in the environment, '_tzset' updates _daylight,
> +     but not _dstbias.  Then if we are switching from a timezone without
> +     DST to a timezone with DST, 'localtime' and friends will apply zero
> +     DST bias, which is incorrect. (When TZ is not defined, '_tzset'
> +     does update _dstbias using values obtained from Windows API
> +     GetTimeZoneInformation.)  Here we fix that blunder by detecting
> +     this situation and forcing _dstbias to be 1 hour.  */
> +  if (tz_env && _daylight && !_dstbias)
> +    _dstbias = -3600;
> +}

You wrote _dstbias should be zero when _daylight was zero, but the
patch doesn't touch _dstbias in that case.  However it whould not
cause a real problem as I wrote.

-- 
Kazuhiro Ito




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.