Skip to content

Commit f7e7b4d

Browse files
committed
win32.c: use _mkgmtime() instead of mktime() in stat()
Conversion to local time seems unnecessary and it apparently causes issues with DST. Fixes #20018, #20061
1 parent 86584ca commit f7e7b4d

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

pod/perldelta.pod

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,18 @@ L</Modules and Pragmata> section.
330330

331331
=over 4
332332

333-
=item XXX-some-platform
333+
=item Windows
334334

335-
XXX
335+
=over 4
336+
337+
=item *
338+
339+
In some cases, timestamps returned by L<stat()|perlfunc/stat> and
340+
L<lstat()|perlfunc/lstat> failed to take daylight saving time into account.
341+
[L<GH #20018|https://github.com/Perl/perl5/issues/20018>]
342+
[L<GH #20061|https://github.com/Perl/perl5/issues/20061>]
343+
344+
=back
336345

337346
=back
338347

win32/win32.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,24 +1469,21 @@ win32_kill(int pid, int sig)
14691469
PERL_STATIC_INLINE
14701470
time_t
14711471
translate_ft_to_time_t(FILETIME ft) {
1472-
SYSTEMTIME st, local_st;
1472+
SYSTEMTIME st;
14731473
struct tm pt;
14741474

1475-
if (!FileTimeToSystemTime(&ft, &st) ||
1476-
!SystemTimeToTzSpecificLocalTime(NULL, &st, &local_st)) {
1475+
if (!FileTimeToSystemTime(&ft, &st))
14771476
return -1;
1478-
}
14791477

14801478
Zero(&pt, 1, struct tm);
1481-
pt.tm_year = local_st.wYear - 1900;
1482-
pt.tm_mon = local_st.wMonth - 1;
1483-
pt.tm_mday = local_st.wDay;
1484-
pt.tm_hour = local_st.wHour;
1485-
pt.tm_min = local_st.wMinute;
1486-
pt.tm_sec = local_st.wSecond;
1487-
pt.tm_isdst = -1;
1488-
1489-
return mktime(&pt);
1479+
pt.tm_year = st.wYear - 1900;
1480+
pt.tm_mon = st.wMonth - 1;
1481+
pt.tm_mday = st.wDay;
1482+
pt.tm_hour = st.wHour;
1483+
pt.tm_min = st.wMinute;
1484+
pt.tm_sec = st.wSecond;
1485+
1486+
return _mkgmtime(&pt);
14901487
}
14911488

14921489
typedef DWORD (__stdcall *pGetFinalPathNameByHandleA_t)(HANDLE, LPSTR, DWORD, DWORD);

0 commit comments

Comments
 (0)