MCPcopy
hub / github.com/moment/luxon / fromISO

Method fromISO

src/interval.js:136–172  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 15

checkFunction · 0.45
parse.test.jsFile · 0.45
rejectsFunction · 0.45
localeWeek.test.jsFile · 0.45
toFormat.test.jsFile · 0.45
endOfWeekIsFunction · 0.45
zone.test.jsFile · 0.45
regexParse.test.jsFile · 0.45
isSameFunction · 0.45
rejectsFunction · 0.45
diff.test.jsFile · 0.45
degrade.test.jsFile · 0.45

Calls 4

fromDateTimesMethod · 0.80
afterMethod · 0.80
beforeMethod · 0.80
invalidMethod · 0.45

Tested by 9

checkFunction · 0.36
rejectsFunction · 0.36
endOfWeekIsFunction · 0.36
isSameFunction · 0.36
rejectsFunction · 0.36
checkFunction · 0.36
fromISOsFunction · 0.36
fromISOsFunction · 0.36
fromISOsFunction · 0.36