@@ -3617,36 +3617,37 @@ export function UnbalanceDurationRelative(
3617
3617
case 'month' :
3618
3618
{
3619
3619
if ( ! calendar ) throw new RangeError ( 'a starting point is required for months balancing' ) ;
3620
+ assertExists ( relativeTo ) ;
3620
3621
// balance years down to months
3621
3622
const dateAdd = calendar . dateAdd ;
3622
3623
const dateUntil = calendar . dateUntil ;
3623
- let relativeToDateOnly : Temporal . PlainDateLike = relativeTo as Temporal . PlainDateLike ;
3624
3624
while ( MathAbs ( years ) > 0 ) {
3625
- const newRelativeTo = CalendarDateAdd ( calendar , relativeToDateOnly , oneYear , undefined , dateAdd ) ;
3625
+ const newRelativeTo = CalendarDateAdd ( calendar , relativeTo , oneYear , undefined , dateAdd ) ;
3626
3626
const untilOptions = ObjectCreate ( null ) ;
3627
3627
untilOptions . largestUnit = 'month' ;
3628
- const untilResult = CalendarDateUntil ( calendar , relativeToDateOnly , newRelativeTo , untilOptions , dateUntil ) ;
3628
+ const untilResult = CalendarDateUntil ( calendar , relativeTo , newRelativeTo , untilOptions , dateUntil ) ;
3629
3629
const oneYearMonths = GetSlot ( untilResult , MONTHS ) ;
3630
- relativeToDateOnly = newRelativeTo ;
3630
+ relativeTo = newRelativeTo ;
3631
3631
months += oneYearMonths ;
3632
3632
years -= sign ;
3633
3633
}
3634
3634
}
3635
3635
break ;
3636
3636
case 'week' :
3637
3637
if ( ! calendar ) throw new RangeError ( 'a starting point is required for weeks balancing' ) ;
3638
+ assertExists ( relativeTo ) ;
3638
3639
// balance years down to days
3639
3640
while ( MathAbs ( years ) > 0 ) {
3640
3641
let oneYearDays ;
3641
- ( { relativeTo, days : oneYearDays } = MoveRelativeDate ( calendar , relativeTo as Temporal . PlainDate , oneYear ) ) ;
3642
+ ( { relativeTo, days : oneYearDays } = MoveRelativeDate ( calendar , relativeTo , oneYear ) ) ;
3642
3643
days += oneYearDays ;
3643
3644
years -= sign ;
3644
3645
}
3645
3646
3646
3647
// balance months down to days
3647
3648
while ( MathAbs ( months ) > 0 ) {
3648
3649
let oneMonthDays ;
3649
- ( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo as Temporal . PlainDate , oneMonth ) ) ;
3650
+ ( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
3650
3651
days += oneMonthDays ;
3651
3652
months -= sign ;
3652
3653
}
@@ -3655,26 +3656,29 @@ export function UnbalanceDurationRelative(
3655
3656
// balance years down to days
3656
3657
while ( MathAbs ( years ) > 0 ) {
3657
3658
if ( ! calendar ) throw new RangeError ( 'a starting point is required for balancing calendar units' ) ;
3659
+ assertExists ( relativeTo ) ;
3658
3660
let oneYearDays ;
3659
- ( { relativeTo, days : oneYearDays } = MoveRelativeDate ( calendar , relativeTo as Temporal . PlainDate , oneYear ) ) ;
3661
+ ( { relativeTo, days : oneYearDays } = MoveRelativeDate ( calendar , relativeTo , oneYear ) ) ;
3660
3662
days += oneYearDays ;
3661
3663
years -= sign ;
3662
3664
}
3663
3665
3664
3666
// balance months down to days
3665
3667
while ( MathAbs ( months ) > 0 ) {
3666
3668
if ( ! calendar ) throw new RangeError ( 'a starting point is required for balancing calendar units' ) ;
3669
+ assertExists ( relativeTo ) ;
3667
3670
let oneMonthDays ;
3668
- ( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo as Temporal . PlainDate , oneMonth ) ) ;
3671
+ ( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
3669
3672
days += oneMonthDays ;
3670
3673
months -= sign ;
3671
3674
}
3672
3675
3673
3676
// balance weeks down to days
3674
3677
while ( MathAbs ( weeks ) > 0 ) {
3675
3678
if ( ! calendar ) throw new RangeError ( 'a starting point is required for balancing calendar units' ) ;
3679
+ assertExists ( relativeTo ) ;
3676
3680
let oneWeekDays ;
3677
- ( { relativeTo, days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo as Temporal . PlainDate , oneWeek ) ) ;
3681
+ ( { relativeTo, days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo , oneWeek ) ) ;
3678
3682
days += oneWeekDays ;
3679
3683
weeks -= sign ;
3680
3684
}
@@ -3713,9 +3717,8 @@ export function BalanceDurationRelative(
3713
3717
3714
3718
switch ( largestUnit ) {
3715
3719
case 'year' : {
3716
- // These conditions are effectively identical (as relativeTo being defined forces calendar to be defined)
3717
- // but checking for their truthiness here helps TypeScript and avoids the need for casts below.
3718
- if ( ! relativeTo || ! calendar ) throw new RangeError ( 'a starting point is required for years balancing' ) ;
3720
+ if ( ! calendar ) throw new RangeError ( 'a starting point is required for years balancing' ) ;
3721
+ assertExists ( relativeTo ) ;
3719
3722
// balance days up to years
3720
3723
let newRelativeTo , oneYearDays ;
3721
3724
( { relativeTo : newRelativeTo , days : oneYearDays } = MoveRelativeDate ( calendar , relativeTo , oneYear ) ) ;
@@ -3757,9 +3760,8 @@ export function BalanceDurationRelative(
3757
3760
break ;
3758
3761
}
3759
3762
case 'month' : {
3760
- // These conditions are effectively identical (as relativeTo being defined forces calendar to be defined)
3761
- // but checking for their truthiness here helps TypeScript and avoids the need for casts below.
3762
- if ( ! relativeTo || ! calendar ) throw new RangeError ( 'a starting point is required for months balancing' ) ;
3763
+ if ( ! calendar ) throw new RangeError ( 'a starting point is required for months balancing' ) ;
3764
+ assertExists ( relativeTo ) ;
3763
3765
// balance days up to months
3764
3766
let newRelativeTo , oneMonthDays ;
3765
3767
( { relativeTo : newRelativeTo , days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
@@ -3772,9 +3774,8 @@ export function BalanceDurationRelative(
3772
3774
break ;
3773
3775
}
3774
3776
case 'week' : {
3775
- // These conditions are effectively identical (as relativeTo being defined forces calendar to be defined)
3776
- // but checking for their truthiness here helps TypeScript and avoids the need for casts below.
3777
- if ( ! relativeTo || ! calendar ) throw new RangeError ( 'a starting point is required for weeks balancing' ) ;
3777
+ if ( ! calendar ) throw new RangeError ( 'a starting point is required for weeks balancing' ) ;
3778
+ assertExists ( relativeTo ) ;
3778
3779
// balance days up to weeks
3779
3780
let newRelativeTo , oneWeekDays ;
3780
3781
( { relativeTo : newRelativeTo , days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo , oneWeek ) ) ;
@@ -5711,9 +5712,8 @@ export function RoundDuration(
5711
5712
let total : number ;
5712
5713
switch ( unit ) {
5713
5714
case 'year' : {
5714
- // These conditions are effectively identical (as relativeTo being defined forces calendar to be defined)
5715
- // but checking for their truthiness here helps TypeScript and avoids the need for casts below.
5716
- if ( ! relativeTo || ! calendar ) throw new RangeError ( 'A starting point is required for years rounding' ) ;
5715
+ if ( ! calendar ) throw new RangeError ( 'A starting point is required for years rounding' ) ;
5716
+ assertExists ( relativeTo ) ;
5717
5717
5718
5718
// convert months and weeks to days by calculating difference(
5719
5719
// relativeTo + years, relativeTo + { years, months, weeks })
@@ -5765,9 +5765,8 @@ export function RoundDuration(
5765
5765
break ;
5766
5766
}
5767
5767
case 'month' : {
5768
- // These conditions are effectively identical (as relativeTo being defined forces calendar to be defined)
5769
- // but checking for their truthiness here helps TypeScript and avoids the need for casts below.
5770
- if ( ! relativeTo || ! calendar ) throw new RangeError ( 'A starting point is required for months rounding' ) ;
5768
+ if ( ! calendar ) throw new RangeError ( 'A starting point is required for months rounding' ) ;
5769
+ assertExists ( relativeTo ) ;
5771
5770
5772
5771
// convert weeks to days by calculating difference(relativeTo +
5773
5772
// { years, months }, relativeTo + { years, months, weeks })
@@ -5812,9 +5811,8 @@ export function RoundDuration(
5812
5811
break ;
5813
5812
}
5814
5813
case 'week' : {
5815
- // These conditions are effectively identical (as relativeTo being defined forces calendar to be defined)
5816
- // but checking for their truthiness here helps TypeScript and avoids the need for casts below.
5817
- if ( ! relativeTo || ! calendar ) throw new RangeError ( 'A starting point is required for weeks rounding' ) ;
5814
+ if ( ! calendar ) throw new RangeError ( 'A starting point is required for weeks rounding' ) ;
5815
+ assertExists ( relativeTo ) ;
5818
5816
// Weeks may be different lengths of days depending on the calendar,
5819
5817
// convert days to weeks in a loop as described above under 'years'.
5820
5818
const sign = MathSign ( days ) ;
0 commit comments