Skip to content

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

Merged
pitdicker merged 1 commit into
chronotope:mainfrom
pitdicker:duration_display
Feb 10, 2024
Merged

Make Display format of Duration conform better to ISO 8601#1328
pitdicker merged 1 commit into
chronotope:mainfrom
pitdicker:duration_display

Conversation

@pitdicker

@pitdicker pitdicker commented Sep 27, 2023

Copy link
Copy Markdown
Collaborator

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

codecov Bot commented Sep 27, 2023

Copy link
Copy Markdown

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.

Comment thread 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
Copy Markdown
Member

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
Copy Markdown
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.

2 participants