Skip to content

<xloctime>: Fix time_get::do_get format strings for %c and %x - #6133

Merged
Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:mainfrom
BrandonPacewic:xloctime-time-get-do-get-format
Mar 24, 2026
Merged

<xloctime>: Fix time_get::do_get format strings for %c and %x#6133
Stephan T. Lavavej (StephanTLavavej) merged 8 commits into
microsoft:mainfrom
BrandonPacewic:xloctime-time-get-do-get-format

Conversation

@BrandonPacewic

@BrandonPacewic Brandon Pacewic (BrandonPacewic) commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #6129.

time_get::do_get hardcoded the wrong format strings for %c and %x in the C locale:

  • %c was "%b %d %H : %M : %S %Y", missing the leading weekday field entirely. It should be "%a %b %e %T %Y" to match what strftime("%c") produces.
  • %x was "%d / %m / %y" (day/month order), but should be "%m/%d/%y" (month/day order) to match strftime("%x").

As the original open issue describes, this is an ABI preserving behavior change. The existing test Dev11_0836436_get_time is updated accordingly and its %x test inputs were written for the old day first format and its comment cited "%d / %m / %y" directly.

The libcxx test std/localization/locale.categories/category.time/locale.time.get/locale.time.get.members/get_one.pass.cpp still fails due to a separate pre-existing bug where do_get does not handle the %% specifier (falls to default: failbit) (#6130). Its entry in expected_results.txt is left in place.

Also updates P0355R7_calendars_and_time_zones_io test inputs for %c and %x, since std::chrono::parse routes those format specifiers through time_get::do_get and the existing inputs were written against the old incorrect format strings.

Force push note 🐱
I force pushed during early preparation of this PR to fix a commit message and add a missing `test.lst` entry before any review had begun. I understand that force pushing during active review is disruptive and I will not do so going forward. 🙃

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the bug Something isn't working label Mar 3, 2026
Comment thread tests/std/tests/GH_006129_time_get_do_get_format/test.cpp Outdated
Comment thread stl/inc/xloctime Outdated
Comment thread tests/std/tests/Dev11_0836436_get_time/test.cpp
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Initial Review to Ready To Merge in STL Code Reviews Mar 18, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks! 😻 I pushed a test change as recommended by Matt Stephanson (@MattStephanson).

@cpplearner S. B. Tam (cpplearner) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes time_get so that it can parse the output of strftime in the "C" locale, which is an improvement.

The format still doesn't match strftime when the locale is not "C", but I think we shouldn't support that scenario. I filed LWG-4541 in the hope that we can get an explicit permission to do whatever we want with locale-dependent specifiers like %c or %x.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Mar 21, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

Stephan T. Lavavej (StephanTLavavej) added a commit to StephanTLavavej/STL that referenced this pull request Mar 21, 2026
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 09cc7d6 into microsoft:main Mar 24, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Mar 24, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

Thanks for fixing this bug! ⏱️ 🗺️ 🌏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<xloctime>: time_get::do_get uses the wrong format for %c and %x

4 participants