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 time interval parsed wrong #271

Open
StefanKern opened this issue Feb 21, 2020 · 2 comments
Open

ISO 8601 time interval parsed wrong #271

StefanKern opened this issue Feb 21, 2020 · 2 comments

Comments

@StefanKern
Copy link

From the wiki we get the following different formats to devine a time interval

There are four ways to express a time interval:

  1. Start and end, such as "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
  2. Start and duration, such as "2007-03-01T13:00:00Z/P1Y2M10DT2H30M"
  3. Duration and end, such as "P1Y2M10DT2H30M/2008-05-11T15:30:00Z"
  4. Duration only, such as "P1Y2M10DT2H30M", with additional context

I tried to parse this formats with moment.range(...) but only the first interval is parsed correctly.
These are my testcyases

'2007-03-01T13:00:00Z/2008-05-11T15:30:00Z',
moment.range('2007-03-01T13:00:00Z/2008-05-11T15:30:00Z').contains(moment("2007-03-02")), // true
moment.range('2007-03-01T13:00:00Z/2008-05-11T15:30:00Z').contains(moment("2007-03-01")), // false
moment.range('2007-03-01T13:00:00Z/2008-05-11T15:30:00Z').contains(moment("2008-05-12")), // false
"2007-03-01T13:00:00Z/P1Y2M10DT2H30M",
moment.range('2007-03-01T13:00:00Z/P1Y2M10DT2H30M').contains(moment("2007-03-02")), // false --> should be TURE!
moment.range('2007-03-01T13:00:00Z/P1Y2M10DT2H30M').contains(moment("2007-03-01")), // false
moment.range('2007-03-01T13:00:00Z/P1Y2M10DT2H30M').contains(moment("2008-05-12")),
"P1Y2M10DT2H30M/2008-05-11T15:30:00Z",
moment.range('P1Y2M10DT2H30M/2008-05-11T15:30:00Z').contains(moment("2007-03-02")), // false --> should be TURE!
moment.range('P1Y2M10DT2H30M/2008-05-11T15:30:00Z').contains(moment("2007-03-01")), // false
moment.range('P1Y2M10DT2H30M/2008-05-11T15:30:00Z').contains(moment("2008-05-12")), // false
"P1Y2M10DT2H30M",
moment.range('P1Y2M10DT2H30M').contains(moment("2007-03-02")), // false --> should be TURE!
moment.range('P1Y2M10DT2H30M').contains(moment("2007-03-01")), // false
moment.range('P1Y2M10DT2H30M').contains(moment("2008-05-12")), // false

Demo: https://stackblitz.com/edit/moment-js-ttpb3c?file=src%2Fapp%2Fapp.component.ts

This means that only the first case is supported, but other cases, which are in the standard, are not supported.

@xyy94813
Copy link

I got this problem too.

And i found PR 259 had been merged.
#259

Before release a new version you can implement it in your project.
It is easy to implement base on moment.duration (moment version large then v2.3?)

@lissau
Copy link

lissau commented Jul 28, 2022

This is still an issue in version 4.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants