icu4x icon indicating copy to clipboard operation
icu4x copied to clipboard

Add ISO-8601 style Duration parsing

Open sffc opened this issue 3 months ago • 3 comments

It would be convenient for users and for writing unit tests if we could parse ISO-8601 duration strings into DateDuration.

Examples:

  • P1D => { days: 1 }
  • P2M1D => { months: 2, days: 1 }
  • P77Y => { years: 77 }

sffc avatar Oct 03 '25 04:10 sffc

@sffc i can work on this issue

zacharyftw avatar Oct 03 '25 13:10 zacharyftw

Thanks! You can learn more about the duration syntax here:

https://en.wikipedia.org/wiki/ISO_8601#Durations

https://tc39.es/proposal-temporal/#prod-TemporalDurationString

Since DateDuration supports only years, months, weeks, and days, we should parse only the date fields from duration strings, and reject duration strings that have time portions after the T. So, for example, we should parse P5M but not PT5M.

This should be exported as a function DateDuration::try_from_str and DateDuration::try_from_utf8 with a corresponding FromStr impl. You can see lots of other examples of signatures of parsing functions throughout ICU4X.

sffc avatar Oct 03 '25 16:10 sffc

can you assign me this @sffc

tanishqshrivas avatar Oct 27 '25 14:10 tanishqshrivas

is this issue fixed? if not i can work on this.

SATVIKsynopsis avatar Dec 14 '25 13:12 SATVIKsynopsis

No need to ask to be assigned. We don't assign backlog issues. Just create a PR linked to this issue.

sffc avatar Dec 15 '25 05:12 sffc

Alright. Will make a pr soon

SATVIKsynopsis avatar Dec 15 '25 06:12 SATVIKsynopsis

@SATVIKsynopsis your other PR #7315 is still draft and not passing tests. I suggest you focus on fixing and landing that one first.

sffc avatar Dec 15 '25 06:12 sffc

Got it thanks for the clarification. I will focus on fixing and landing #7315 first.

SATVIKsynopsis avatar Dec 15 '25 06:12 SATVIKsynopsis