-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chronat: Clock formatting #1846
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
Conversation
| 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}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but ... still
There was a problem hiding this comment.
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.
mnatsuhara
left a comment
There was a problem hiding this 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.
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.