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

From: Eli Zaretskii <[email-masked]>
Date: Mon, 26 May 2025 19:05:54 +0300

> Date: Mon, 26 May 2025 23:50:51 +0900
> From: Kazuhiro Ito <[email-masked]>
> Cc: [email-masked],
> 	[email-masked]
> 
> > 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!

Thanks, will install soon.

> > +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.

I concluded that what we need to ensure is the other way around: if
_daylight is non-zero, _dstbias must also be non-zero.  When _daylight
is zero, the value of _dstbias doesn't matter, because localtyime and
friends don't apply _dstbias in that case.