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> Formatting: C++20's Final Boss #1870

Merged
merged 41 commits into from
Apr 23, 2021

Commits on Apr 15, 2021

  1. Squashed chronat changes.

    Co-authored-by: Elnar Dakeshov <55715127+eldakesh-ms@users.noreply.github.com>
    Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
    3 people committed Apr 15, 2021
    Configuration menu
    Copy the full SHA
    2118d1e View commit details
    Browse the repository at this point in the history
  2. Fix tests.

    StephanTLavavej committed Apr 15, 2021
    Configuration menu
    Copy the full SHA
    33e3804 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    cdfa88c View commit details
    Browse the repository at this point in the history
  4. chronat: Add year and year_month_day formatting (microsoft#1840)

    * <chronat>: Add year and year_month_day formatting
    
    This one is a biggie. The main things changed are the way that
    specifiers are handled and delegated.
    
    The general idea behind formatting time is that you can take segments of
    a type and format them individually. For example, you can take the year
    out of year_month_day and do the exact same operations you can do with a
    normal year. The `_Is_type_valid` function recursively checks if a
    parent type can be formatted by its children. The other functions didn't
    really need much more finessing, the `tm` structure already has all the
    fields we need to hold all the time info (simultaniously) and the
    formatters work off that.
    
    The big change here is in moving some "basic" formatters into our own
    function and not relying on `get_time` to format them. The main reason
    is that `get_time` does not play with invalid ranges, at all. A day of
    `40` is always illegal, but we need to be able to format it, especially
    in the face of `operator <<`. We could have kept what we had before, but
    then it becomes a clear problem that we cannot use `%F` for a
    `year_month_day` that has an invalid day, so I am seperating all the
    integral formatters out into that function. Again, because of the nested
    nature of times, we recurse in this function.
    
    Note that function currently uses `format_to` in probably a very
    inneficient way. I am all ears on how to improve that.
    
    * Clang test
    
    * Finesse the tests
    
    * review
    
    * Comment update
    
    Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
    
    * PR fixes
    
    Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
    eldakesh-ms and mnatsuhara authored Apr 15, 2021
    Configuration menu
    Copy the full SHA
    0aeb5ea View commit details
    Browse the repository at this point in the history
  5. Add hh_mm_ss operator<<

    eldakesh-ms committed Apr 15, 2021
    Configuration menu
    Copy the full SHA
    206727e View commit details
    Browse the repository at this point in the history
  6. Fix tests

    eldakesh-ms committed Apr 15, 2021
    Configuration menu
    Copy the full SHA
    1cb654b View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    e7b705a View commit details
    Browse the repository at this point in the history
  8. add test for u w

    mnatsuhara committed Apr 15, 2021
    2 Configuration menu
    Copy the full SHA
    5505ea3 View commit details
    Browse the repository at this point in the history

Commits on Apr 16, 2021

  1. Configuration menu
    Copy the full SHA
    4c236a3 View commit details
    Browse the repository at this point in the history
  2. Modifier table update

    eldakesh-ms committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    5bf0c50 View commit details
    Browse the repository at this point in the history
  3. Update the modifier table, use uint8_t.

    This follows N4885 [tab:time.format.spec]'s order,
    and adds {'z', _EO_mod} which was missing.
    StephanTLavavej committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    1187292 View commit details
    Browse the repository at this point in the history
  4. Robuster OOB handling

    eldakesh-ms committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    838cd1f View commit details
    Browse the repository at this point in the history
  5. Add general time filler

    eldakesh-ms committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    3a19af7 View commit details
    Browse the repository at this point in the history
  6. Remove failed type checks

    eldakesh-ms committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    889fe20 View commit details
    Browse the repository at this point in the history
  7. Add/centralize formatters, replace operators.

    * Mark _Fill_tm() as _NODISCARD.
    
    * Teach _Fill_tm() to handle year_month_day_MEOW by directly extracting
      components when possible, and constructing a year_month_day{}
      temporary only when necessary.
    
    * Replace all of the operator<<() implementations for calendrical types
      with their "Effects Equivalent To" implementations from the Standard
      (modified to follow our conventions and actually compile). This should
      handle the setw(8) case mentioned by P1361R2 section 6 item 5, whereas
      implementing operator<<() by calling other operator<<() is
      (apparently) doomed.
    
    * Note that each operator<<() won't compile until all of the formatters
      that it depends on have been implemented.
    
    * Teach _Is_valid_type() to accept year_month_day_MEOW.
    
    * Now that _Fill_tm() centralizes the "decompose a calendrical type into
      its components" logic, we can further centralize the formatter
      definitions with _Fill_tm_formatter. Unlike the operator<<() overloads
      (where I added all types), I'm not adding formatters for unimplemented
      types here. When they're implemented, they should also be able to use
      _Fill_tm_formatter, unless they need unusual processing beyond what
      _Fill_tm() provides.
    
    * In P0355R7_calendars_and_time_zones_formatting/test.cpp, add
      placeholder tests, and comment out test_hh_mm_ss_formatter()'s
      implementation for now.
    StephanTLavavej committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    7ee91b1 View commit details
    Browse the repository at this point in the history
  8. Update libcxx skips.

    StephanTLavavej committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    48eb7f8 View commit details
    Browse the repository at this point in the history
  9. Add hh_mm_ss formatter

    Adds the formatter with special bounds check so that `put_time` doesn't
    assert.
    
    Small bugfix/simplification for when `ok()` needs to be checked. Before
    we call `put_time`, we should always bounds check.
    
    Custom %S writer added (and %T calls it too). This is necessary for
    proper fractional second printing.
    eldakesh-ms committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    84760ea View commit details
    Browse the repository at this point in the history
  10. Add month_day, month_day_last, and year_month formatting

    Not too many tests but they reuse a lot of the same pathways. Wouldn't
    hurt to test more but the operator<< are fully passthrough to format so
    it's not too scary.
    eldakesh-ms committed Apr 16, 2021
    Configuration menu
    Copy the full SHA
    29b7094 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    f6ba00d View commit details
    Browse the repository at this point in the history
  12. chronat: Allow day from month_day_last conditionally (microsoft#1845)

    Thanks to matt and stat on discord for mentioning these edge cases.
    
    I originally thought that you can't get a day from `month_day_last`, but
    it clearly makes sense, for most months. I changed some machinery around
    so that we can always intercept a specifier, which means that we need to
    do manual checking in the writer for localization.
    
    This PR is more to illustrate how a specifier may be intercepted, and
    that testing need only be done for specific types.
    eldakesh-ms authored Apr 16, 2021
    Configuration menu
    Copy the full SHA
    0814ca2 View commit details
    Browse the repository at this point in the history
  13. chronat: Clock formatting (microsoft#1846)

    * chronat: Clock formatting
    
    Adds formatting for clocks!
    
    Moved _Custom_write into the formatter so it can do special things
    (write timezones).
    
    _Write_seconds now writes leap seconds as 60 for utc clock time points.
    
    Taught _Fill_tm to work with time_points (in reality only system_clock
    and local_clock work).
    
    Add operator<< for all clocks except local-time-format-t (because I'm
    still not sure what that is).
    
    The base formatter stores a timezone abbreviation. This is only useful
    for the clocks, but it seemed like the simplest way to implement this
    feature.
    
    * Remove unnecessary _CharT param for _Custom_write.
    
    This is a member function of _Chrono_formatter which
    is already templated on _CharT.
    
    * typename _Ty::clock.
    
    Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
    eldakesh-ms and StephanTLavavej authored Apr 16, 2021
    Configuration menu
    Copy the full SHA
    a0f6558 View commit details
    Browse the repository at this point in the history

Commits on Apr 17, 2021

  1. wd, wdi formatting (microsoft#1847)

    * wd, wdi formatting
    
    * Update libcxx skips.
    
    * Arrange formatters in Standard order.
    
    Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
    mnatsuhara and StephanTLavavej authored Apr 17, 2021
    Configuration menu
    Copy the full SHA
    d418366 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8aeda0c View commit details
    Browse the repository at this point in the history
  3. <chrono> formatting: fix UB, various cleanups (microsoft#1848)

    * Fix UB, various cleanups.
    
    * Optimize with common_type_t<_Duration, days>.
    
    Co-authored-by: MattStephanson <68978048+MattStephanson@users.noreply.github.com>
    StephanTLavavej and MattStephanson authored Apr 17, 2021
    Configuration menu
    Copy the full SHA
    6c06f23 View commit details
    Browse the repository at this point in the history
  4. <chrono>: Implement exception class constructors (microsoft#1849)

    * hh_mm_ss::hours() is already an absolute value.
    
    Co-authored-by: statementreply <statementreply@gmail.com>
    
    * Implement nonexistent_local_time/ambiguous_local_time.
    
    * Test nonexistent_local_time/ambiguous_local_time.
    
    * Fix P0355R7_calendars_and_time_zones_time_zones.
    
    We can't use floating-point durations because the exception
    constructors in [time.zone.exception] will stream local_time<Duration>,
    and [time.clock.local] implements that by streaming sys_time<Duration>,
    and that's constrained by [time.clock.system.nonmembers]
    to reject floating-point durations.
    
    Co-authored-by: statementreply <statementreply@gmail.com>
    StephanTLavavej and statementreply authored Apr 17, 2021
    Configuration menu
    Copy the full SHA
    d718499 View commit details
    Browse the repository at this point in the history

Commits on Apr 18, 2021

  1. <chrono> formatting: weekday_last, month_weekday, `month_weekda…

    …y_last` (microsoft#1854)
    
    * Add/test weekday_last, month_weekday, month_weekday_last.
    
    * In _Fill_tm():
      + weekday_indexed and weekday_last can share code.
      + month_weekday and month_weekday_last have different accessors.
      + Cleanup: Unify the code for year_month_weekday and year_month_weekday_last.
    * In _Is_valid_type():
      + weekday, weekday_indexed, and weekday_last all support the "weekday types".
      + month_weekday and month_weekday_last support "month types" and "weekday types".
        (As mentioned above, their accessors are actually weekday_indexed() and
        weekday_last(), but it seemed pointless to have separate cases to "recurse"
        into the weekday_indexed and weekday_last types, when the answer is always
        the same.)
      + Remove TRANSITION and change the final static_assert to
        "should be unreachable", which is the pattern that we use elsewhere.
    * Add the new formatters, all powered by _Fill_tm_formatter.
    
    In P0355R7_calendars_and_time_zones_formatting/test.cpp:
    
    * Rename charT to CharT for consistency (this is needed by the STR macro,
      if it were ever used in these functions).
    * Add empty_braces_helper() to test both format("{}") and operator<<.
      This should supersede stream_helper() but I'm not making that change here.
    * Test the new types.
    * Implement tests for year_month_day_last, year_month_weekday, and
      year_month_weekday_last now that the necessary formatters are available.
    * Call the new test functions.
    
    * Update libcxx skips for C++20 features.
    StephanTLavavej authored Apr 18, 2021
    Configuration menu
    Copy the full SHA
    d705b61 View commit details
    Browse the repository at this point in the history
  2. <chrono> formatting: More cleanups (microsoft#1857)

    * Rearrange tests to follow Standard order.
    
    No other changes.
    
    * Move _Chrono_formatter into namespace chrono.
    
    No changes other than (greatly reduced!) qualification and formatting.
    
    _Fill_tm_formatter is still directly within std,
    as it's the base class for std::formatter.
    
    * Rename _Chrono_specs to _Chrono_spec.
    
    Drop "with literal chars" from a comment; this reflected our earlier,
    incorrect understanding.
    
    This also renames _Custom_write()'s parameter from _Specs to _Spec,
    avoiding shadowing a data member.
    StephanTLavavej authored Apr 18, 2021
    Configuration menu
    Copy the full SHA
    1f874eb View commit details
    Browse the repository at this point in the history

Commits on Apr 19, 2021

  1. <chrono> formatting: Simplify test (microsoft#1859)

    * Replace stream_helper with empty_braces_helper.
    
    * Replace assert(format(STR("{}"), A) == B) with empty_braces_helper(A, B).
    
    * Remove duplicate lines.
    
    * Simplify choose_literal, use STR consistently.
    StephanTLavavej authored Apr 19, 2021
    Configuration menu
    Copy the full SHA
    c06416c View commit details
    Browse the repository at this point in the history
  2. chronat: Add duration formatter (microsoft#1861)

    * chronat: Add duration formatter
    
    Special specifiers for duration are `j q Q`.
    
    Otherwise duration is very similar to `hh_mm_ss` except that times are
    interpreted as time from midnight. I thought this would mean that
    negative times are yesterday, but we just append a `-` instead, which
    means we should round instead of flooring to a day when computing
    hh/mm/ss.
    
    Other behavior is pretty simple.
    
    * Add typename.
    
    * Comments
    
    Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
    eldakesh-ms and StephanTLavavej authored Apr 19, 2021
    Configuration menu
    Copy the full SHA
    229dfde View commit details
    Browse the repository at this point in the history

Commits on Apr 20, 2021

  1. <chrono> formatting: sys_info, local_info, feature-test macro (m…

    …icrosoft#1860)
    
    * Define and test the feature-test macro.
    
    * Implement and test sys_info and local_info.
    
    * Update libcxx skips.
    
    * Additionally test zero and half-hour offsets.
    
    * Print `seconds offset` and `minutes save`.
    
    * Add TRANSITION comment.
    StephanTLavavej authored Apr 20, 2021
    Configuration menu
    Copy the full SHA
    39c722f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    d69d7ba View commit details
    Browse the repository at this point in the history
  3. <chrono>: Add %j support and expand %aAuw (microsoft#1864)

    * <chrono>: Add %j support and expand %aAuw
    
    Adds %j support to all the classes that can benefit from it.
    This means all year_month_day* but and month_last (but only for
    January).
    
    Changes %aAuw to throw on invalid weekdays, but still work if the
    weekday is explicitly ok (so a bad year_month_day will always throw but
    a bad year_month_weekday can still print the weekday if that portion is
    ok).
    
    * Add month_day support
    
    * Make put_time strings uniformly
    eldakesh-ms authored Apr 20, 2021
    Configuration menu
    Copy the full SHA
    65ad8a7 View commit details
    Browse the repository at this point in the history
  4. <chrono: Rewrite %r spec for C locale (microsoft#1865)

    put_time(%r) does the wrong thing when we use the C locale, due to some
    internal machinery. It could get fixed further down level, but that
    change is a lot more impactful. Instead, we simply rewrite %r when the C
    locale is used in chrono.
    
    This basically has to do with the way that _Strftime, _Gettnames, and
    expand_time work together. _Gettnames returns a copy of its data and
    expand_time figures out the locale based on pointer comparison.
    eldakesh-ms authored Apr 20, 2021
    Configuration menu
    Copy the full SHA
    d488200 View commit details
    Browse the repository at this point in the history
  5. <chrono>: Fix hh_mm_ss subsecond formatting for floats (microsoft#1866)

    * <chrono>: Fix hh_mm_ss subsecond formatting for floats
    
    Before, the same formatting string was used for floats and integrals.
    This meant that large floats were formatted using exponent notaion and
    small floats were not, and it also meant there was an extra period in a
    time, as the subseconds could be fractions of a subsecond (say .4
    nanoseconds). Now if the subseconds are floats, we force fixed
    formatting to get the right number of leading zeroes and a precision of
    0 to round off fractions of subseconds.
    
    * Floor subseconds
    eldakesh-ms authored Apr 20, 2021
    Configuration menu
    Copy the full SHA
    cc2651d View commit details
    Browse the repository at this point in the history

Commits on Apr 21, 2021

  1. <chrono>: Fix utc_clock seconds formatting (microsoft#1868)

    Co-authored-by: MattStephanson <68978048+MattStephanson@users.noreply.github.com>
    Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
    3 people authored Apr 21, 2021
    Configuration menu
    Copy the full SHA
    cec735c View commit details
    Browse the repository at this point in the history
  2. <chrono> formatting: extend %r, add %g %G %U %V %W (microsoft#1869

    )
    
    * Various cleanups.
    
    * Use `else` with `if constexpr` to avoid dead code.
    
    * Some helpers can be `static`.
    
    * Add a newline between non-chained `if` statements.
    
    * Extend %r to all types (local_time_format, zoned_time).
    
    * Implement %g %G %U %V %W.
    StephanTLavavej authored Apr 21, 2021
    Configuration menu
    Copy the full SHA
    e015c35 View commit details
    Browse the repository at this point in the history
  3. <chrono>: Fine grained bounds checking (microsoft#1871)

    Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
    Co-authored-by: mnatsuhara <46756417+mnatsuhara@users.noreply.github.com>
    3 people authored Apr 21, 2021
    Configuration menu
    Copy the full SHA
    d652eab View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    360e631 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    bd5b397 View commit details
    Browse the repository at this point in the history

Commits on Apr 22, 2021

  1. Configuration menu
    Copy the full SHA
    7c177d0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ab1001c View commit details
    Browse the repository at this point in the history