@@ -4756,8 +4756,8 @@ export function RoundDuration(
4756
4756
// First convert time units up to days, if rounding to days or higher units.
4757
4757
// If rounding relative to a ZonedDateTime, then some days may not be 24h.
4758
4758
// TS doesn't know that `dayLengthNs` is only used if the unit is day or
4759
- // larger. This makes the cast below acceptable .
4760
- let dayLengthNs : JSBI = undefined as unknown as JSBI ;
4759
+ // larger. We'll cast away `undefined` when it's used lower down below .
4760
+ let dayLengthNs : JSBI | undefined ;
4761
4761
if ( unit === 'year' || unit === 'month' || unit === 'week' || unit === 'day' ) {
4762
4762
nanoseconds = TotalDurationNanoseconds ( 0 , hours , minutes , seconds , milliseconds , microseconds , nanosecondsParam , 0 ) ;
4763
4763
let intermediate ;
@@ -4823,9 +4823,12 @@ export function RoundDuration(
4823
4823
// the duration. This lets us do days-or-larger rounding using BigInt
4824
4824
// math which reduces precision loss.
4825
4825
oneYearDays = MathAbs ( oneYearDays ) ;
4826
- const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ) ;
4826
+ // dayLengthNs is never undefined if unit is `day` or larger.
4827
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4828
+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ! ) ;
4827
4829
nanoseconds = JSBI . add (
4828
- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4830
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4831
+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
4829
4832
nanoseconds
4830
4833
) ;
4831
4834
const rounded = RoundNumberToIncrement (
@@ -4879,9 +4882,12 @@ export function RoundDuration(
4879
4882
( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
4880
4883
}
4881
4884
oneMonthDays = MathAbs ( oneMonthDays ) ;
4882
- const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ) ;
4885
+ // dayLengthNs is never undefined if unit is `day` or larger.
4886
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4887
+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ! ) ;
4883
4888
nanoseconds = JSBI . add (
4884
- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4889
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4890
+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
4885
4891
nanoseconds
4886
4892
) ;
4887
4893
const rounded = RoundNumberToIncrement (
@@ -4909,9 +4915,12 @@ export function RoundDuration(
4909
4915
( { relativeTo, days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo , oneWeek ) ) ;
4910
4916
}
4911
4917
oneWeekDays = MathAbs ( oneWeekDays ) ;
4912
- const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ) ;
4918
+ // dayLengthNs is never undefined if unit is `day` or larger.
4919
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4920
+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ! ) ;
4913
4921
nanoseconds = JSBI . add (
4914
- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4922
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4923
+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
4915
4924
nanoseconds
4916
4925
) ;
4917
4926
const rounded = RoundNumberToIncrement (
@@ -4926,7 +4935,9 @@ export function RoundDuration(
4926
4935
break ;
4927
4936
}
4928
4937
case 'day' : {
4929
- const divisor = dayLengthNs ;
4938
+ // dayLengthNs is never undefined if unit is `day` or larger.
4939
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4940
+ const divisor = dayLengthNs ! ;
4930
4941
nanoseconds = JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( days ) ) , nanoseconds ) ;
4931
4942
const rounded = RoundNumberToIncrement (
4932
4943
nanoseconds ,
0 commit comments