-
Notifications
You must be signed in to change notification settings - Fork 526
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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 { |
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.
What's the point of this loop?
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.
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.
fab1030
to
0454b09
Compare
The
Display
format ofDuration
currently converts all values greater than 24 hours to a value with days. But in ISO 8601P1D
has a different meaning fromPT86400S
.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 aFromStr
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.