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

From: Eli Zaretskii <[email-masked]>
Date: Sat, 24 May 2025 11:14:04 +0300

> Date: Sat, 24 May 2025 13:32:54 +0900
> From: Kazuhiro Ito <[email-masked]>
> Cc: [email-masked],
> 	[email-masked]
> 
> > Note that this:
> > 
> >   (let ((time (encode-time '(0 0 12 20 5 2025 nil nil t))))
> >     (setenv "TZ" "JST-9")
> >     (decode-time time "est5edt"))
> > 
> > yields the expected result.
> 
> Yes, but it is true only if you had never called `(setenv "TZ" nil)'.
> Your example yields unexpected result if TZ environmental variable is
> not set at starting emacs (and it is Windows's default).  Probably you
> set TZ environmental variable.

No, TZ is not set on my system.  But my timezone does have DST rules,
so maybe that somehow affects the results.

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