@@ -144,3 +144,182 @@ test.each(badInputs)("Interval.fromISO will return invalid for [%s]", (s) => {
144144 expect ( i . isValid ) . toBe ( false ) ;
145145 expect ( i . invalidReason ) . toBe ( "unparsable" ) ;
146146} ) ;
147+
148+ describe ( "Interval.fromISO defaults missing values in end to start" , ( ) => {
149+ test ( "Gregorian, end just time" , ( ) => {
150+ const i = Interval . fromISO ( "1988-04-15T09/15:30" ) ;
151+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-04:00" ) ;
152+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-15T15:30:00.000-04:00" ) ;
153+ } ) ;
154+ test ( "Gregorian, end just time and zone" , ( ) => {
155+ const i = Interval . fromISO ( "1988-04-15T09/15:30-07:00" ) ;
156+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-04:00" ) ;
157+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-15T18:30:00.000-04:00" ) ;
158+ } ) ;
159+ test ( "Gregorian, end just day" , ( ) => {
160+ const i = Interval . fromISO ( "1988-04-15T09/17" ) ;
161+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-04:00" ) ;
162+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-17T00:00:00.000-04:00" ) ;
163+ } ) ;
164+ test ( "Gregorian, end day and time" , ( ) => {
165+ const i = Interval . fromISO ( "1988-04-15T09/17T15:30" ) ;
166+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-04:00" ) ;
167+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-17T15:30:00.000-04:00" ) ;
168+ } ) ;
169+ test ( "Gregorian, end month and day" , ( ) => {
170+ const i = Interval . fromISO ( "1988-04-15T09/05-17" ) ;
171+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-04:00" ) ;
172+ expect ( i . end . toISO ( ) ) . toBe ( "1988-05-17T00:00:00.000-04:00" ) ;
173+ } ) ;
174+ test ( "Gregorian, end month, day and time" , ( ) => {
175+ const i = Interval . fromISO ( "1988-04-15T09/05-17T15:30" ) ;
176+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-04:00" ) ;
177+ expect ( i . end . toISO ( ) ) . toBe ( "1988-05-17T15:30:00.000-04:00" ) ;
178+ } ) ;
179+ test ( "Gregorian with zone in options and partial date" , ( ) => {
180+ const i = Interval . fromISO ( "1988-04-15T09/19" , { zone : "UTC-06:00" } ) ;
181+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-06:00" ) ;
182+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-19T00:00:00.000-06:00" ) ;
183+ } ) ;
184+ test ( "Gregorian with zone in options and partial date and time" , ( ) => {
185+ const i = Interval . fromISO ( "1988-04-15T09/19T13:00" , { zone : "UTC-06:00" } ) ;
186+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-06:00" ) ;
187+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-19T13:00:00.000-06:00" ) ;
188+ } ) ;
189+ test ( "Gregorian with zone in options and full date and time" , ( ) => {
190+ const i = Interval . fromISO ( "1988-04-15T09/1989-03-01T13:00" , { zone : "UTC-06:00" } ) ;
191+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-06:00" ) ;
192+ expect ( i . end . toISO ( ) ) . toBe ( "1989-03-01T13:00:00.000-06:00" ) ;
193+ } ) ;
194+ test ( "Gregorian with zone in options and end zone" , ( ) => {
195+ const i = Interval . fromISO ( "1988-04-15T09/16T15:00-07:00" , { zone : "UTC-06:00" } ) ;
196+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-06:00" ) ;
197+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-16T16:00:00.000-06:00" ) ;
198+ } ) ;
199+ test ( "Gregorian with zone in options, setZone and end zone" , ( ) => {
200+ const i = Interval . fromISO ( "1988-04-15T09/16T15:00-07:00" , {
201+ zone : "UTC-06:00" ,
202+ setZone : true ,
203+ } ) ;
204+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000-06:00" ) ;
205+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-16T15:00:00.000-07:00" ) ;
206+ } ) ;
207+ test ( "Gregorian with start zone" , ( ) => {
208+ const i = Interval . fromISO ( "1988-04-15T09:00:00+01:00/17T15:30" ) ;
209+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T04:00:00.000-04:00" ) ;
210+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-17T10:30:00.000-04:00" ) ;
211+ } ) ;
212+ test ( "Gregorian with start zone and zone in options" , ( ) => {
213+ const i = Interval . fromISO ( "1988-04-15T09:00:00+01:00/15T15:00" , { zone : "UTC-06:00" } ) ;
214+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T02:00:00.000-06:00" ) ;
215+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-15T08:00:00.000-06:00" ) ;
216+ } ) ;
217+ test ( "Gregorian with start zone and setZone" , ( ) => {
218+ const i = Interval . fromISO ( "1988-04-15T09:00:00+01:00/15T15:00" , { setZone : true } ) ;
219+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000+01:00" ) ;
220+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-15T15:00:00.000+01:00" ) ;
221+ } ) ;
222+ test ( "Gregorian with two zones" , ( ) => {
223+ const i = Interval . fromISO ( "1988-04-15T09:00:00+01:00/15T16:00+02:00" ) ;
224+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T04:00:00.000-04:00" ) ;
225+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-15T10:00:00.000-04:00" ) ;
226+ } ) ;
227+ test ( "Gregorian with two zones and setZone" , ( ) => {
228+ const i = Interval . fromISO ( "1988-04-15T09:00:00+01:00/15T16:00+02:00" , { setZone : true } ) ;
229+ expect ( i . start . toISO ( ) ) . toBe ( "1988-04-15T09:00:00.000+01:00" ) ;
230+ expect ( i . end . toISO ( ) ) . toBe ( "1988-04-15T16:00:00.000+02:00" ) ;
231+ } ) ;
232+
233+ // Week dates
234+ test ( "Week, end just time" , ( ) => {
235+ const i = Interval . fromISO ( "2025-W20-1T09/15:30" ) ;
236+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
237+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-12T15:30:00.000-04:00" ) ;
238+ } ) ;
239+ test ( "Week, end just time and zone" , ( ) => {
240+ const i = Interval . fromISO ( "2025-W20-1T09/15:30-07:00" ) ;
241+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
242+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-12T18:30:00.000-04:00" ) ;
243+ } ) ;
244+ test ( "Week, end week day" , ( ) => {
245+ const i = Interval . fromISO ( "2025-W20-1T09/3T15:30" ) ;
246+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
247+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-14T15:30:00.000-04:00" ) ;
248+ } ) ;
249+ test ( "Week, end week number and week day" , ( ) => {
250+ const i = Interval . fromISO ( "2025-W20-1T09/W21-3T15:30" ) ;
251+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
252+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-21T15:30:00.000-04:00" ) ;
253+ } ) ;
254+
255+ // Ordinal dates
256+ test ( "Ordinal, end just time" , ( ) => {
257+ const i = Interval . fromISO ( "2025-132T09/15:30" ) ;
258+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
259+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-12T15:30:00.000-04:00" ) ;
260+ } ) ;
261+ test ( "Ordinal, end just time and zone" , ( ) => {
262+ const i = Interval . fromISO ( "2025-132T09/15:30-07:00" ) ;
263+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
264+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-12T18:30:00.000-04:00" ) ;
265+ } ) ;
266+ test ( "Ordinal, end with ordinal" , ( ) => {
267+ const i = Interval . fromISO ( "2025-132T09/135T15:30" ) ;
268+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
269+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
270+ } ) ;
271+
272+ // Mixed
273+ test ( "Gregorian, end just weekday" , ( ) => {
274+ const i = Interval . fromISO ( "2025-05-12T09/4T15:30" ) ;
275+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
276+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
277+ } ) ;
278+ test ( "Gregorian, end weekNumber and weekday" , ( ) => {
279+ const i = Interval . fromISO ( "2025-05-12T09/W21-1T15:30" ) ;
280+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
281+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-19T15:30:00.000-04:00" ) ;
282+ } ) ;
283+ test ( "Gregorian, end just ordinal" , ( ) => {
284+ const i = Interval . fromISO ( "2025-05-12T09/135T15:30" ) ;
285+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
286+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
287+ } ) ;
288+
289+ test ( "Week date, end just day" , ( ) => {
290+ const i = Interval . fromISO ( "2025-W20-1T09/15T15:30" ) ;
291+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
292+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
293+ } ) ;
294+ test ( "Week date, end month and day" , ( ) => {
295+ const i = Interval . fromISO ( "2025-W20-1T09/06-15T15:30" ) ;
296+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
297+ expect ( i . end . toISO ( ) ) . toBe ( "2025-06-15T15:30:00.000-04:00" ) ;
298+ } ) ;
299+ test ( "Week date, end just ordinal" , ( ) => {
300+ const i = Interval . fromISO ( "2025-W20-1T09/135T15:30" ) ;
301+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
302+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
303+ } ) ;
304+
305+ test ( "Ordinal, end just day" , ( ) => {
306+ const i = Interval . fromISO ( "2025-132T09/15T15:30" ) ;
307+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
308+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
309+ } ) ;
310+ test ( "Ordinal, end month and day" , ( ) => {
311+ const i = Interval . fromISO ( "2025-132T09/06-15T15:30" ) ;
312+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
313+ expect ( i . end . toISO ( ) ) . toBe ( "2025-06-15T15:30:00.000-04:00" ) ;
314+ } ) ;
315+ test ( "Ordinal, end just weekday" , ( ) => {
316+ const i = Interval . fromISO ( "2025-132T09/4T15:30" ) ;
317+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
318+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-15T15:30:00.000-04:00" ) ;
319+ } ) ;
320+ test ( "Ordinal, end weekNumber and weekday" , ( ) => {
321+ const i = Interval . fromISO ( "2025-132T09/W21-1T15:30" ) ;
322+ expect ( i . start . toISO ( ) ) . toBe ( "2025-05-12T09:00:00.000-04:00" ) ;
323+ expect ( i . end . toISO ( ) ) . toBe ( "2025-05-19T15:30:00.000-04:00" ) ;
324+ } ) ;
325+ } ) ;
0 commit comments