question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duration#toISO() may not conform to ISO 8601.

See original GitHub issue

Weeks 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
  • 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.

https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/time/Period.html#parse(java.lang.CharSequence)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
munierujpcommented, Apr 1, 2019

It seems that we need to buy to see it… 💸

https://www.iso.org/standard/70908.html

2reactions
icambroncommented, Aug 4, 2019

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 days
  • toISOWeeks converts the duration to weeks via as('weeks') and then just formats in that number of weeks
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found