STL
STL copied to clipboard
<chrono>: `zoned_time` and `current_zone` ignore DST preference on Windows 11 and Server 2022
Describe the bug
Testing the migration of Kodi to std::chrono
(xbmc/xbmc#18727), the bug has been reported in STL chrono implementation where
time zones with DST adjustment preference grayed-out (unavailable) or disabled by user result in 1 hour difference between Kodi local time and the Windows Explorer local time.
For example, (UTC-06:00) Guadalajara, Mexico City, Monterey
has no DST policy and the bug is shown on screenshot (notice top-right clock of Kodi vs bottom-right of Windows Explorer tray and the one in Date and Time Settings applet!):
For (UTC-06:00) Central Time (US & Canada)
there is a preference to apply DST adjustment or not. Turning DST adjustment ON shows the proper time in Kodi:
while turning it OFF manifests the bug:
Command-line test case
C:\Temp>type repro.cpp
#include <chrono>
#include <iostream>
int main() {
const std::chrono::zoned_time cur_time{ std::chrono::current_zone(),
std::chrono::system_clock::now() };
std::cout << cur_time << '\n';
}
C:\Temp>cl /EHsc /W4 /WX /std:c++latest .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.41.34120 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.
repro.cpp
Microsoft (R) Incremental Linker Version 14.41.34120.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
C:\Temp> REM (UTC-06:00) Guadalajara, Mexico City, Monterey - DST pref grayed out (bad!)
C:\Temp>time
The current time is: 1:05:09.35
Enter the new time:
C:\Temp>repro.exe
2024-10-01 02:05:13.0396870 CDT`
C:\Temp> REM (UTC-06:00) Central Time (US & Canada) - DST preference on (good!)
C:\Temp>time
The current time is: 2:06:44.42
Enter the new time:
C:\Temp>repro.exe
2024-10-01 02:06:47.3969896 CDT
C:\Temp> REM (UTC-06:00) Central Time (US & Canada) - DST preference off (bad!)
C:\Temp>time
The current time is: 1:08:39.69
Enter the new time:
C:\Temp>repro.exe
2024-10-01 02:08:42.3091382 CDT
Expected behavior
DST preferences should be honored!
STL version
- Option 1: Visual Studio version
C:\Temp>"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -property catalog_productDisplayVersion
17.11.4
Additional context
None