Skip to content

Conversation

@StephanTLavavej
Copy link
Member

  • Various cleanups:
    • Use else with if constexpr to avoid dead code.
    • The helpers _Check_modifier, _Is_valid_type, and _Fmt_string can be static.
    • Add a newline between non-chained if statements.
  • Extend the %r replacement logic to all types (local_time_format() and zoned_time).
    • This is as simple as removing the condition for hh_mm_ss and updating the tests accordingly.
    • For clarity, because %r now prints a space, I'm adding commas.
  • Implement %g %G (ISO week-based year) and %U %V %W (various flavors of week number).
    • Thanks to @mnatsuhara for noticing that this was missing.
    • These are supported for the types that represent a specific point in time (at the granularity of a day or better). That's time_point (which also powers local_time_format() and zoned_time) and the year_month_day family.
    • As a special bonus, year_month can print the ISO week-based year as long as we're not in January or December (when ISO and Gregorian have differences).
    • In _Is_valid_type, we list %g %G as being valid for year_month, and %g %G %U %V %W (in table-sorted order) as being valid for the year_month_day family. This cascades to time_point, local_time_format(), and zoned_time.
    • In _Custom_write, we need to detect year_month and reject Jan/Dec. Otherwise, we manually print the year by mapping the ISO types to Gregorian types (this grants us the correct padding and number of digits).
    • put_time handles everything else. 😸
  • To test this:
    • I have a bunch of cases for sys_days observing various transition points.
    • year_month tests the rejected and accepted cases.
    • Same bunch of cases for year_month_day (since this one is "fundamental").
    • The rest of the types just have a cursory check that the specifiers work, since the core logic is shared.

* Use `else` with `if constexpr` to avoid dead code.

* Some helpers can be `static`.

* Add a newline between non-chained `if` statements.
@StephanTLavavej StephanTLavavej added cxx20 C++20 feature chrono C++20 chrono labels Apr 21, 2021
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner April 21, 2021 09:35
@StephanTLavavej StephanTLavavej merged commit e015c35 into microsoft:chronat2 Apr 21, 2021
@StephanTLavavej StephanTLavavej deleted the chronat2_stl branch April 21, 2021 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chrono C++20 chrono cxx20 C++20 feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant