> > ;; 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 #include #include 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