@@ -4780,8 +4780,8 @@ export function RoundDuration(
4780
4780
// First convert time units up to days, if rounding to days or higher units.
4781
4781
// If rounding relative to a ZonedDateTime, then some days may not be 24h.
4782
4782
// TS doesn't know that `dayLengthNs` is only used if the unit is day or
4783
- // larger. This makes the cast below acceptable .
4784
- let dayLengthNs : JSBI = undefined as unknown as JSBI ;
4783
+ // larger. We'll cast away `undefined` when it's used lower down below .
4784
+ let dayLengthNs : JSBI | undefined ;
4785
4785
if ( unit === 'year' || unit === 'month' || unit === 'week' || unit === 'day' ) {
4786
4786
nanoseconds = TotalDurationNanoseconds ( 0 , hours , minutes , seconds , milliseconds , microseconds , nanosecondsParam , 0 ) ;
4787
4787
let intermediate ;
@@ -4847,9 +4847,12 @@ export function RoundDuration(
4847
4847
// the duration. This lets us do days-or-larger rounding using BigInt
4848
4848
// math which reduces precision loss.
4849
4849
oneYearDays = MathAbs ( oneYearDays ) ;
4850
- const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ) ;
4850
+ // dayLengthNs is never undefined if unit is `day` or larger.
4851
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4852
+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ! ) ;
4851
4853
nanoseconds = JSBI . add (
4852
- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4854
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4855
+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
4853
4856
nanoseconds
4854
4857
) ;
4855
4858
const rounded = RoundNumberToIncrement (
@@ -4903,9 +4906,12 @@ export function RoundDuration(
4903
4906
( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
4904
4907
}
4905
4908
oneMonthDays = MathAbs ( oneMonthDays ) ;
4906
- const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ) ;
4909
+ // dayLengthNs is never undefined if unit is `day` or larger.
4910
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4911
+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ! ) ;
4907
4912
nanoseconds = JSBI . add (
4908
- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4913
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4914
+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
4909
4915
nanoseconds
4910
4916
) ;
4911
4917
const rounded = RoundNumberToIncrement (
@@ -4933,9 +4939,12 @@ export function RoundDuration(
4933
4939
( { relativeTo, days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo , oneWeek ) ) ;
4934
4940
}
4935
4941
oneWeekDays = MathAbs ( oneWeekDays ) ;
4936
- const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ) ;
4942
+ // dayLengthNs is never undefined if unit is `day` or larger.
4943
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4944
+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ! ) ;
4937
4945
nanoseconds = JSBI . add (
4938
- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4946
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4947
+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
4939
4948
nanoseconds
4940
4949
) ;
4941
4950
const rounded = RoundNumberToIncrement (
@@ -4950,7 +4959,9 @@ export function RoundDuration(
4950
4959
break ;
4951
4960
}
4952
4961
case 'day' : {
4953
- const divisor = dayLengthNs ;
4962
+ // dayLengthNs is never undefined if unit is `day` or larger.
4963
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4964
+ const divisor = dayLengthNs ! ;
4954
4965
nanoseconds = JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( days ) ) , nanoseconds ) ;
4955
4966
const rounded = RoundNumberToIncrement (
4956
4967
nanoseconds ,
0 commit comments