Duration#toISO() may not conform to ISO 8601.
See original GitHub issueWeeks should be expressed as days, isn’t it?
cf. https://en.wikipedia.org/wiki/ISO_8601#Durations
Example
const duration = Duration.fromObject({
years: 3,
months: 6,
weeks: 1,
days: 4,
hours: 12,
minutes: 30,
seconds: 5
})
console.log(duration.toISO())
- expected:
P3Y6M11DT12H30M5S
- 1[weeks] + 4[days] = 7[days] + 4[days] = 11[days] ->
11D
- 1[weeks] + 4[days] = 7[days] + 4[days] = 11[days] ->
- actual:
P3Y6M1W4DT12H30M5S
1W4D
FYI
Description of Java’s Period#parse()
:
ISO-8601 does not permit mixing between the PnYnMnD and PnW formats. Any week-based input is multiplied by 7 and treated as a number of days.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Conversion of milliseconds duration to ISO 8601 precise string ...
Try: String iso = Duration.ofMillis(millis).toString();. toString() returns the duration using the ISO-8601 seconds based representation.
Read more >Datetime string must match ISO 8601 format. Can't figure it out.
Solved: Unable to process template language expressions for action 'Condition' at line '1' and column '17747': 'In function 'formatDateTime', the.
Read more >Format time period links - ISO Codes - Workiva Support
Using the ISO 8601 duration codes eliminates ambiguity when your XBRL documents ... these facts would not comply with the SEC regulations.
Read more >ISO 8601 — Date and time format
Looking for an unambiguous calendar-and-clock format that is internationally understood? It's time for ISO 8601. This ISO standard helps ...
Read more >toIsoString - Kotlin Programming Language
Returns an ISO-8601 based string representation of this duration. The returned value is presented in the format PThHmMs.fS , where h , m...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems that we need to buy to see it… 💸
https://www.iso.org/standard/70908.html
I think it’s a little awkward that we only get the
W
representation if the duration data is just so. Will only serve to surprise people that the strings look really different in some situations. So let’s have separate methods:toISO
always converts weeks to daystoISOWeeks
converts the duration to weeks viaas('weeks')
and then just formats in that number of weeks