@@ -15,7 +15,6 @@ import {
15
15
NANOSECONDS ,
16
16
CALENDAR ,
17
17
INSTANT ,
18
- TIME_ZONE ,
19
18
CreateSlots ,
20
19
GetSlot ,
21
20
SetSlot
@@ -236,7 +235,7 @@ export class Duration {
236
235
}
237
236
238
237
let largestUnit = ES . GetTemporalUnit ( roundTo , 'largestUnit' , 'datetime' , undefined , [ 'auto' ] ) ;
239
- let relativeTo = ES . ToRelativeTemporalObject ( roundTo ) ;
238
+ const { relativeTo, timeZoneRec } = ES . ToRelativeTemporalObject ( roundTo ) ;
240
239
const roundingIncrement = ES . ToTemporalRoundingIncrement ( roundTo ) ;
241
240
const roundingMode = ES . ToTemporalRoundingMode ( roundTo , 'halfExpand' ) ;
242
241
let smallestUnit = ES . GetTemporalUnit ( roundTo , 'smallestUnit' , 'datetime' , undefined ) ;
@@ -301,7 +300,12 @@ export class Duration {
301
300
if ( zonedRelativeTo && plainRelativeToWillBeUsed ) {
302
301
// Convert a ZonedDateTime relativeTo to PlainDate only if needed in one
303
302
// of the operations below, because the conversion is user visible
304
- plainRelativeTo = ES . ToTemporalDate ( zonedRelativeTo ) ;
303
+ const dt = ES . GetPlainDateTimeFor (
304
+ timeZoneRec ,
305
+ GetSlot ( zonedRelativeTo , INSTANT ) ,
306
+ GetSlot ( zonedRelativeTo , CALENDAR )
307
+ ) ;
308
+ plainRelativeTo = ES . TemporalDateTimeToDate ( dt ) ;
305
309
}
306
310
307
311
( { years, months, weeks, days } = ES . UnbalanceDurationRelative (
@@ -328,7 +332,8 @@ export class Duration {
328
332
smallestUnit ,
329
333
roundingMode ,
330
334
plainRelativeTo ,
331
- zonedRelativeTo
335
+ zonedRelativeTo ,
336
+ timeZoneRec
332
337
) ) ;
333
338
if ( zonedRelativeTo ) {
334
339
( { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
@@ -346,7 +351,8 @@ export class Duration {
346
351
roundingIncrement ,
347
352
smallestUnit ,
348
353
roundingMode ,
349
- zonedRelativeTo
354
+ zonedRelativeTo ,
355
+ timeZoneRec
350
356
) ) ;
351
357
}
352
358
( { days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES . BalanceDuration (
@@ -358,7 +364,8 @@ export class Duration {
358
364
microseconds ,
359
365
nanoseconds ,
360
366
largestUnit ,
361
- zonedRelativeTo
367
+ zonedRelativeTo ,
368
+ timeZoneRec
362
369
) ) ;
363
370
( { years, months, weeks, days } = ES . BalanceDurationRelative (
364
371
years ,
@@ -392,7 +399,7 @@ export class Duration {
392
399
} else {
393
400
totalOf = ES . GetOptionsObject ( totalOf ) ;
394
401
}
395
- const relativeTo = ES . ToRelativeTemporalObject ( totalOf ) ;
402
+ const { relativeTo, timeZoneRec } = ES . ToRelativeTemporalObject ( totalOf ) ;
396
403
const unit = ES . GetTemporalUnit ( totalOf , 'unit' , 'datetime' , ES . REQUIRED ) ;
397
404
398
405
let zonedRelativeTo = ES . IsTemporalZonedDateTime ( relativeTo ) ? relativeTo : undefined ;
@@ -402,15 +409,20 @@ export class Duration {
402
409
if ( zonedRelativeTo !== undefined && plainRelativeToWillBeUsed ) {
403
410
// Convert a ZonedDateTime relativeTo to PlainDate only if needed in one
404
411
// of the operations below, because the conversion is user visible
405
- plainRelativeTo = ES . ToTemporalDate ( zonedRelativeTo ) ;
412
+ const dt = ES . GetPlainDateTimeFor (
413
+ timeZoneRec ,
414
+ GetSlot ( zonedRelativeTo , INSTANT ) ,
415
+ GetSlot ( zonedRelativeTo , CALENDAR )
416
+ ) ;
417
+ plainRelativeTo = ES . TemporalDateTimeToDate ( dt ) ;
406
418
}
407
419
408
420
// Convert larger units down to days
409
421
( { years, months, weeks, days } = ES . UnbalanceDurationRelative ( years , months , weeks , days , unit , plainRelativeTo ) ) ;
410
422
// If the unit we're totalling is smaller than `days`, convert days down to that unit.
411
423
let intermediate ;
412
424
if ( zonedRelativeTo ) {
413
- intermediate = ES . MoveRelativeZonedDateTime ( zonedRelativeTo , years , months , weeks , 0 ) ;
425
+ intermediate = ES . MoveRelativeZonedDateTime ( zonedRelativeTo , timeZoneRec , years , months , weeks , 0 ) ;
414
426
}
415
427
let balanceResult = ES . BalancePossiblyInfiniteDuration (
416
428
days ,
@@ -421,7 +433,8 @@ export class Duration {
421
433
microseconds ,
422
434
nanoseconds ,
423
435
unit ,
424
- intermediate
436
+ intermediate ,
437
+ timeZoneRec
425
438
) ;
426
439
if ( balanceResult === 'positive overflow' ) {
427
440
return Infinity ;
@@ -445,7 +458,8 @@ export class Duration {
445
458
unit ,
446
459
'trunc' ,
447
460
plainRelativeTo ,
448
- zonedRelativeTo
461
+ zonedRelativeTo ,
462
+ timeZoneRec
449
463
) ;
450
464
return total ;
451
465
}
@@ -532,19 +546,18 @@ export class Duration {
532
546
) {
533
547
return 0 ;
534
548
}
535
- const relativeTo = ES . ToRelativeTemporalObject ( options ) ;
549
+ const { relativeTo, timeZoneRec } = ES . ToRelativeTemporalObject ( options ) ;
536
550
537
551
const calendarUnitsPresent = y1 !== 0 || y2 !== 0 || mon1 !== 0 || mon2 !== 0 || w1 !== 0 || w2 !== 0 ;
538
552
539
553
if ( ES . IsTemporalZonedDateTime ( relativeTo ) && ( calendarUnitsPresent || d1 != 0 || d2 !== 0 ) ) {
540
554
const instant = GetSlot ( relativeTo , INSTANT ) ;
541
- const timeZone = GetSlot ( relativeTo , TIME_ZONE ) ;
542
555
const calendar = GetSlot ( relativeTo , CALENDAR ) ;
543
- const precalculatedDateTime = ES . GetPlainDateTimeFor ( timeZone , instant , calendar ) ;
556
+ const precalculatedDateTime = ES . GetPlainDateTimeFor ( timeZoneRec , instant , calendar ) ;
544
557
545
558
const after1 = ES . AddZonedDateTime (
546
559
instant ,
547
- timeZone ,
560
+ timeZoneRec ,
548
561
calendar ,
549
562
y1 ,
550
563
mon1 ,
@@ -560,7 +573,7 @@ export class Duration {
560
573
) ;
561
574
const after2 = ES . AddZonedDateTime (
562
575
instant ,
563
- timeZone ,
576
+ timeZoneRec ,
564
577
calendar ,
565
578
y2 ,
566
579
mon2 ,
0 commit comments