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

Make Display format of Duration conform better to ISO 8601 #1328

Merged
merged 1 commit into from
Feb 10, 2024

Conversation

pitdicker
Copy link
Collaborator

@pitdicker pitdicker commented Sep 27, 2023

The Display format of Duration currently converts all values greater than 24 hours to a value with days. But in ISO 8601 P1D has a different meaning from PT86400S.

If we get a duration type that properly supports the ISO 8601 format with different components (#1282), I think we should fix the simple Duration type to always write only seconds. We later may be able to share the parser and a FromStr implementation.

I ported the code to count the significant fractional digits in nanos from #1290.
It should find a shared place once one of these PRs has landed.

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (58f1f37) 93.41% compared to head (fab1030) 91.51%.
Report is 51 commits behind head on main.

❗ Current head fab1030 differs from pull request most recent head 0454b09. Consider uploading reports for the commit 0454b09 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1328      +/-   ##
==========================================
- Coverage   93.41%   91.51%   -1.91%     
==========================================
  Files          34       38       +4     
  Lines       16754    17316     +562     
==========================================
+ Hits        15651    15846     +195     
- Misses       1103     1470     +367     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/duration.rs Outdated
// Count the number of significant digits, while removing all trailing zero's.
let mut figures = 9usize;
let mut fraction_digits = abs.nanos;
loop {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the point of this loop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To count the number of significant digits, and removing all trailing zero's. I.e. repeatedly divide nanos by 10.
I do not know a cleaner way to write it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants