moment-range
moment-range copied to clipboard
ISO 8601 time interval parsed wrong
From the wiki we get the following different formats to devine a time interval
There are four ways to express a time interval:
- Start and end, such as "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
- Start and duration, such as "2007-03-01T13:00:00Z/P1Y2M10DT2H30M"
- Duration and end, such as "P1Y2M10DT2H30M/2008-05-11T15:30:00Z"
- 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.
I got this problem too.
And i found PR 259 had been merged. https://github.com/rotaready/moment-range/pull/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?)
This is still an issue in version 4.0.2