Skip to content

Conversation

@eldakesh-ms
Copy link
Contributor

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 time zone abbreviation. This is only useful
for the clocks, but it seemed like the simplest way to implement this
feature.

Based on #1845, so that needs to merge first.

@eldakesh-ms eldakesh-ms requested a review from a team as a code owner April 16, 2021 19:37
auto format(const _CHRONO gps_time<_Duration>& _Val, _FormatContext& _FormatCtx) {
const auto _Sys = _CHRONO sys_time<_Duration>{_Val.time_since_epoch()}
+ (_CHRONO sys_days{_CHRONO year{1980} / 1 / _CHRONO Sunday[1]}
- _CHRONO sys_days{_CHRONO year{1970} / 1 / 1});
Copy link
Contributor

Choose a reason for hiding this comment

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

Screams in math x / 1 / 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case this is confusing, it's specifying a date (in year/month/day order), not dividing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but ... still

Copy link
Member

Choose a reason for hiding this comment

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

I plan to refactor this a bit in a followup commit - not because I think there's anything wrong with / 1 / 1 (it's idiomatic for <chrono>, just like how cats + dogs is not commutative for string, or how my_path / dir / dir is valid for path), but because the Standard depicts January etc. and I think this can be boiled down to a constexpr constant for readability and debug codegen.

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.
@StephanTLavavej StephanTLavavej added chrono C++20 chrono cxx20 C++20 feature labels Apr 16, 2021
Copy link
Contributor

@mnatsuhara mnatsuhara left a comment

Choose a reason for hiding this comment

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

Barring the test failures which I think STL has addressed, this looks good! I'll have to take a closer look at local-time-format-t, I either didn't notice that before or I don't remember what I thought about it 😋

This is a member function of _Chrono_formatter which
is already templated on _CharT.
@StephanTLavavej StephanTLavavej merged commit a0f6558 into microsoft:chronat2 Apr 16, 2021
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.

4 participants