* Create an Interval from an ISO 8601 string. * Accepts ` / `, ` / `, and ` / ` formats. * @param {string} text - the ISO string to parse * @param {Object} [opts] - options to pass DateTime#fromISO and optionally Duration#fromISO * @s
(text, opts)
| 134 | * @return {Interval} |
| 135 | */ |
| 136 | static fromISO(text, opts) { |
| 137 | const [s, e] = (text || "").split("/", 2); |
| 138 | if (s && e) { |
| 139 | let start, startIsValid; |
| 140 | try { |
| 141 | start = DateTime.fromISO(s, opts); |
| 142 | startIsValid = start.isValid; |
| 143 | } catch (e) { |
| 144 | startIsValid = false; |
| 145 | } |
| 146 | |
| 147 | let end, endIsValid; |
| 148 | try { |
| 149 | end = DateTime.fromISO(e, opts); |
| 150 | endIsValid = end.isValid; |
| 151 | } catch (e) { |
| 152 | endIsValid = false; |
| 153 | } |
| 154 | |
| 155 | if (startIsValid && endIsValid) { |
| 156 | return Interval.fromDateTimes(start, end); |
| 157 | } |
| 158 | |
| 159 | if (startIsValid) { |
| 160 | const dur = Duration.fromISO(e, opts); |
| 161 | if (dur.isValid) { |
| 162 | return Interval.after(start, dur); |
| 163 | } |
| 164 | } else if (endIsValid) { |
| 165 | const dur = Duration.fromISO(s, opts); |
| 166 | if (dur.isValid) { |
| 167 | return Interval.before(end, dur); |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | return Interval.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Check if an object is an Interval. Works across context boundaries |