Skip to content
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

ISO-8601 support for Duration #55698

Open
dumazy opened this issue May 13, 2024 · 1 comment
Open

ISO-8601 support for Duration #55698

dumazy opened this issue May 13, 2024 · 1 comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-enhancement A request for a change that isn't a bug

Comments

@dumazy
Copy link

dumazy commented May 13, 2024

I'm currently missing support for the ISO-8601 standard when it comes to Duration.

ISO 8601 Durations are expressed using the following format, where (n) is replaced by the value for each of the date and time elements that follow the (n):

P(n)Y(n)M(n)DT(n)H(n)M(n)S

Where:

P is the duration designator (referred to as "period"), and is always placed at the beginning of the duration.
Y is the year designator that follows the value for the number of years.
M is the month designator that follows the value for the number of months.
W is the week designator that follows the value for the number of weeks.
D is the day designator that follows the value for the number of days.
T is the time designator that precedes the time components.
H is the hour designator that follows the value for the number of hours.
M is the minute designator that follows the value for the number of minutes.
S is the second designator that follows the value for the number of seconds.

source: https://www.digi.com/resources/documentation/digidocs/90001488-13/reference/r_iso_8601_duration_format.htm

I'd love to see to see a Duration.parse(String isoDurationString) method and a toIso8601String() just like DateTime has. This will allow us to easily (de)serialize durations.

Some example of this notation:

  • PT3H30M: 3 hours and 30 minutes
  • P2W1D: 2 weeks and 1 day
  • P1Y10DT3H: 1 year, 10 days and 1 hour
@lrhn
Copy link
Member

lrhn commented May 13, 2024

The Dart Duration class is not compatible with ISO 8601 durations, since it doesn't support durations longer than a day (I guess a week could work, being defined as seven days). It's not even compatible with ISO 8601 days, since those are calendar days which can support time zone changes, and the Dart Duration days are a fixed 864e5 milliseconds.

There is no support for months or years at all, since those do not have a fixed duration, and the Duration class represents a fixed number of microseconds.

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-enhancement A request for a change that isn't a bug labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants