Skip to content

Conversation

cpplearner
Copy link
Contributor

@cpplearner cpplearner commented May 31, 2025

This PR adds a fallback time zone abbreviation of the form -05 or +0530 when the system's code page cannot represent the localized time zone short ID produced by ICU. Previously such time zone short ID would result in ERROR_NO_UNICODE_TRANSLATION exceptions.

The numeric offset form (-05 or +0530) is chosen because it is similar to the time zone abbreviation in tzdb, and distinguishable from ICU's output.

The behavior depends on the current user locale and the current code page. For ICU 77.1, the following locales have time zone short ID with non-ASCII characters, and thus might be affected by this fallback: am, ar, as, bg, blo, brx, ckb, cs, dz, fa, ff_Adlm, ga, gd, he, hi, ii, km, ks, ks_Deva, ku, mai, ml, mni, nqo, sa, sat, sd, sd_Deva, si, sk, vi, xnr. In addition, the following locales have non-ASCII character (U+2212 or U+2013) as the minus sign, and thus are also affected: et, eu, fa, fr, lij, lt, se, sv.

No tests are added because the en locale is unaffected.

Fixes #3158
Fixes #5482

@cpplearner cpplearner requested a review from a team as a code owner May 31, 2025 07:04
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews May 31, 2025
@StephanTLavavej StephanTLavavej added bug Something isn't working chrono C++20 chrono labels Jun 1, 2025
@StephanTLavavej StephanTLavavej self-assigned this Jun 1, 2025
@StephanTLavavej
Copy link
Member

Thanks! 😻 I adjusted the code slightly, then manually verified that it still correctly prints both minutes and whole hours (by brain-surgery nulling out the abbrev pointer in the debugger).

@StephanTLavavej StephanTLavavej removed their assignment Jun 3, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Jun 3, 2025
@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Jun 11, 2025
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 029ce56 into microsoft:main Jun 14, 2025
48 checks passed
@github-project-automation github-project-automation bot moved this from Merging to Done in STL Code Reviews Jun 14, 2025
@StephanTLavavej
Copy link
Member

Thanks for figuring out how to fix this in a reasonable way! 😻 🗺️ 🕥

@cpplearner cpplearner deleted the patch-1 branch June 14, 2025 13:46
}

_Info->_Err = __std_tzdb_error::_Success;
_Info->_Abbrev = _Fallback_abbrev.release();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting after a merge, but does this release() call means we are leaking memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't leaking memory. The returned __std_tzdb_sys_info* will be stored in a unique_ptr<__std_tzdb_sys_info, _Tzdb_deleter<__std_tzdb_sys_info>>, which will call __std_tzdb_delete_sys_info in its destructor, which will perform delete[] _Info->_Abbrev;

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
Projects
Archived in project
3 participants