Skip to content

Conversation

@chiphogg
Copy link
Member

@chiphogg chiphogg commented Aug 2, 2024

Currently, we have a single generic correspondence for all chrono
durations. This is perfectly unit safe, but it means we have no labels
for any duration type, including common types like std::chrono::hours.
This means that as_quantity(std::chrono::hours{3}) would print as
"3 [UNLABELED UNIT]" instead of "3 h".

This PR defines a special correspondence for each commonly used chrono
duration type, which fixes the above behaviour.

As part of doing this, we found a missing dependency on :quantity, so
we added it in the BUILD file.

Fixes #216.

Currently, we have a single generic correspondence for all chrono
durations.  This is perfectly unit safe, but it means we have no labels
for any duration type, including common types like `std::chrono::hours`.
This means that `as_quantity(std::chrono::hours{3})` would print as
`"3 [UNLABELED UNIT]"` instead of `"3 h"`.

This PR defines a special correspondence for each commonly used chrono
duration type, which fixes the above behaviour.

As part of doing this, we found a missing dependency on `:quantity`, so
we added it in the BUILD file.

Fixes #216.
@chiphogg chiphogg added the release notes: ✨ lib (enhancement) PR enhancing the library code label Aug 2, 2024
@chiphogg chiphogg requested a review from geoffviola August 2, 2024 15:41
chiphogg and others added 3 commits August 4, 2024 11:38
Co-authored-by: Michael Hordijk <hoffbrinkle@gmail.com>
Copy link
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

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

Looks useful. Tests look good.

@chiphogg chiphogg merged commit f77cc5e into main Aug 5, 2024
@chiphogg chiphogg deleted the chiphogg/prefixed-seconds#216 branch August 5, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes: ✨ lib (enhancement) PR enhancing the library code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use prefixed seconds when possible for chrono-equivalent units

4 participants