Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<chrono>: Cannot parse "23:59:59" as system_clock::time_point on older Windows versions #2163

Closed
statementreply opened this issue Aug 28, 2021 · 5 comments · Fixed by #2705
Closed
Labels
bug Something isn't working chrono C++20 chrono fixed Something works now, yay!

Comments

@statementreply
Copy link
Contributor

Describe the bug
Originally reported at DevCom-1465261.

auto& db = std::chrono::get_tzdb_list(); throws the runtime exception “The specified module could not be found.” on windows server 2019.
[...]
I am only dealing with UTC but the chrono implementation accesses the tzdb regardless in certain special cases even though it never actually uses the result.
e.g. parsing a date string containing the time “23:59:59” causes a tzdb load internally.

Command-line test case

C:\Users\He\source\test>type chronat.cpp
#include <chrono>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>

using namespace std;
using namespace std::chrono;

int main() {
    try {
        system_clock::time_point t;
        if (istringstream{"2021-08-28 23:59:59"} >> parse("%F %T"s, t)) {
            cout << t << "\n";
        } else {
            cout << "parse failed\n";
        }
    } catch (const exception& e) {
        cout << "error: " << e.what() << "\n";
    }
    return 0;
}
C:\Users\He\source\test>cl /EHsc /W4 /WX /std:c++latest chronat.cpp
用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.30.30423 版
版权所有(C) Microsoft Corporation。保留所有权利。

/std:c++latest 作为最新的 C++
working 草稿中的语言功能预览提供。我们希望你提供有关 bug 和改进建议的反馈。
但是,请注意,这些功能按原样提供,没有支持,并且会随着工作草稿的变化
而更改或移除。有关详细信息,请参阅
https://go.microsoft.com/fwlink/?linkid=2045807。

chronat.cpp
Microsoft (R) Incremental Linker Version 14.30.30423.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:chronat.exe
chronat.obj

On Windows 10 21H1:

C:\Users\He\source\test>.\chronat.exe
2021-08-28 23:59:59.0000000

On Windows 7 SP1:

C:\Users\He\Desktop>.\chronat.exe
error: 参数错误。

Expected behavior
On older systems without leap second support, parsing "23:59:59" as system_clock::time_point should work just fine.

STL version
Microsoft Visual Studio Community 2022 Preview (64 位)
版本 17.0.0 Preview 3.1

@statementreply statementreply changed the title <chrono>: Cannot parse "23:59:59" as system_clock::time_point on older Windows versions <chrono>: Cannot parse "23:59:59" as system_clock::time_point on older Windows versions Aug 28, 2021
@MattStephanson
Copy link
Contributor

Is it feasible to populate the tzdb_list with leap seconds, but no time zones, if ICU isn't found? I think there are some systems that support leap seconds but don't have ICU, so there would be some value to not falling back to a static leap second list in that case.

@StephanTLavavej StephanTLavavej added the bug Something isn't working label Aug 31, 2021
@StephanTLavavej
Copy link
Member

@MattStephanson That would affect a single Win10 version, but it happens to be the Windows Server 2019 version, so it might be worthwhile. https://github.com/microsoft/STL/wiki/Changelog#vs-2019-1610 mentioned:

Specifically, updating the leap second database requires Windows 10 version 1809 or later, and time zones require icu.dll which is provided by Windows 10 version 1903/19H1 or later. This applies to both client and server OSes; note that Windows Server 2019 is based on Windows 10 version 1809.

@statementreply I agree with your expected behavior.

@statementreply
Copy link
Contributor Author

After a second thought, I think there are two separate issues here:

  1. Accessing leap second info fails if ICU is not available.
  2. If a date/time string represents 23:59:59 UTC deleted by a negative leap second, which is otherwise a valid value for sys_time, should parsing sys_time from it succeed or fail?

@MattStephanson
Copy link
Contributor

After a second thought, I think there are two separate issues here:

True, but even if we changed course on checking leap second validity, we'd still have to fix (1) because it's not specific to sys_time or validation. Many operations implicitly need the leap second list, such as formatting or parsing utc_time and various clock_cast paths.

@mnatsuhara mnatsuhara added the chrono C++20 chrono label Sep 1, 2021
@mnatsuhara
Copy link
Contributor

Thanks for bringing this up, noting that #1911 is also related.

manxorist added a commit to OpenMPT/openmpt that referenced this issue Apr 14, 2022
…dern OpenMPT and libopenmpt builds. Older versions of Windows 10 are still supported by legacy builds. Any of the removed Windows 10 versions are only supported for Windows 10 Enterprise by now, and not for consumer versions. Newer VS2022 functionality (like std::chrono timezone handling, see <microsoft/STL#1911> and <microsoft/STL#2163>) does not target these outdated Windows 10 versions any more. See <https://bugs.openmpt.org/view.php?id=1555>.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@17241 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this issue May 27, 2022
… to disable std::chrono date handling completely for MSVC when targeting Windows earlier than Windows 10 1903 due to <microsoft/STL#1911> and <microsoft/STL#2163>.

[Ref] mpt/base/detect_quirks.hpp: Add MPT_LIBCXX_QUIRK_NO_CHRONO_DATE_PARSE tp disable std::chrono for date parsing in VS2022 due to <https://developercommunity.visualstudio.com/t/stdchronoget-tzdb-list-memory-leak/1644641> / <microsoft/STL#2504>.


git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@17377 56274372-70c3-4bfc-bfc3-4c3a0b034d27
manxorist added a commit to OpenMPT/openmpt that referenced this issue May 28, 2022
…20 mode.

[Ref] mptTime: Use std::chrono::system_clock for unix time instead of time_t in C++20 mode. This automatically makes date handling year2038-correct in C++20 mode.
[Ref] mptTime: Add a custom gregorian date type mpt::Date::UTC to use instead of C struct tm.
[Ref] UpdateCheck: Use mpt::Date::Unix instead of time_t.
[Mod] UpdateCheck: Store last update timestamp as Unix seconds instead of YYYY-MM-DD HH:MM. On update, reset to 0.
[Ref] mptTime: Disable std::chrono date handling completely for MSVC when targeting Windows earlier than Windows 10 1903 due to <microsoft/STL#1911> and <microsoft/STL#2163>.
[Mod] OpenMPT: Version is now 1.31.00.12


git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@17383 56274372-70c3-4bfc-bfc3-4c3a0b034d27
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chrono C++20 chrono fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants