Subject: Re: bug#11281: DST has not effect on windows XP when system DST adjustment is disabled

From: Kazuhiro Ito <[email-masked]>
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