tolu / ISO8601-duration

Node/Js-module for parsing and making sense of ISO8601-durations
92 stars 10 forks source link

Error while parsing fraction #32

Closed RHOOPH closed 11 months ago

RHOOPH commented 1 year ago

The Doc says Fractions are allowed on the smallest unit in the string, e.g. P0.5D or PT1.0001S but not PT0.5M0.1S.

However parse("P0.5D") causes error

image

Link to the example

Fractions in Years, Months and Weeks also causes the same error.

tolu commented 1 year ago

Thanks for the issue, are you willing to create a PR with a fix?

tolu commented 11 months ago

I agree that the wikipedia article implies that fractions can be used in Date values, however since Temporal throws a fit (invalid duration) for that I'll stick to their interpretation and close this issue 🙏


try {
  Temporal.Duration.from("PT0.5Y").total({
    unit: "second",
    relativeTo: relativeDate.toISOString(),
  });
} catch (e) {
  // RangeError: invalid duration: PT0.5Y
  console.error(e);
}```