@@ -1129,6 +1129,15 @@ export function LargerOfTwoTemporalUnits<T1 extends Temporal.DateTimeUnit, T2 ex
1129
1129
return unit1 ;
1130
1130
}
1131
1131
1132
+ function MergeLargestUnitOption < T extends Temporal . DateTimeUnit > (
1133
+ optionsParam : Temporal . DifferenceOptions < T > | undefined ,
1134
+ largestUnit : T
1135
+ ) : Temporal . DifferenceOptions < T > {
1136
+ let options = optionsParam ;
1137
+ if ( options === undefined ) options = ObjectCreate ( null ) ;
1138
+ return { ...options , largestUnit } ;
1139
+ }
1140
+
1132
1141
export function ToPartialRecord < B extends AnyTemporalLikeType > ( bagParam : B , fieldsParam : ReadonlyArray < keyof B > ) {
1133
1142
// External callers are limited to specific types, but this function's
1134
1143
// implementation uses generic property types. The casts below (and at the
@@ -4098,7 +4107,7 @@ function DifferenceISODateTime(
4098
4107
const date1 = CreateTemporalDate ( y1 , mon1 , d1 , calendar ) ;
4099
4108
const date2 = CreateTemporalDate ( y2 , mon2 , d2 , calendar ) ;
4100
4109
const dateLargestUnit = LargerOfTwoTemporalUnits ( 'day' , largestUnit ) ;
4101
- const untilOptions = { ... options , largestUnit : dateLargestUnit } ;
4110
+ const untilOptions = MergeLargestUnitOption ( options , dateLargestUnit ) ;
4102
4111
// TODO untilOptions doesn't want to compile as it seems that smallestUnit is not clamped?
4103
4112
// Type 'SmallestUnit<DateTimeUnit> | undefined' is not assignable to type
4104
4113
// 'SmallestUnit<"year" | "month" | "day" | "week"> | undefined'.
@@ -4274,7 +4283,7 @@ export function DifferenceTemporalPlainDate(
4274
4283
if ( operation === 'since' ) roundingMode = NegateTemporalRoundingMode ( roundingMode ) ;
4275
4284
const roundingIncrement = ToTemporalRoundingIncrement ( options , undefined , false ) ;
4276
4285
4277
- const untilOptions = { ... options , largestUnit } ;
4286
+ const untilOptions = MergeLargestUnitOption ( options , largestUnit ) ;
4278
4287
let { years, months, weeks, days } = CalendarDateUntil ( calendar , plainDate , other , untilOptions ) ;
4279
4288
4280
4289
if ( smallestUnit !== 'day' || roundingIncrement !== 1 ) {
@@ -4511,7 +4520,7 @@ export function DifferenceTemporalPlainYearMonth(
4511
4520
const otherDate = CalendarDateFromFields ( calendar , { ...otherFields , day : 1 } ) ;
4512
4521
const thisDate = CalendarDateFromFields ( calendar , { ...thisFields , day : 1 } ) ;
4513
4522
4514
- const untilOptions = { ... options , largestUnit } ;
4523
+ const untilOptions = MergeLargestUnitOption ( options , largestUnit ) ;
4515
4524
let { years, months } = CalendarDateUntil ( calendar , thisDate , otherDate , untilOptions ) ;
4516
4525
4517
4526
if ( smallestUnit !== 'month' || roundingIncrement !== 1 ) {
@@ -4598,7 +4607,7 @@ export function DifferenceTemporalZonedDateTime(
4598
4607
'or smaller because day lengths can vary between time zones due to DST or time zone offset changes.'
4599
4608
) ;
4600
4609
}
4601
- const untilOptions = { ... options , largestUnit } ;
4610
+ const untilOptions = MergeLargestUnitOption ( options , largestUnit ) ;
4602
4611
( { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } =
4603
4612
DifferenceZonedDateTime ( ns1 , ns2 , timeZone , calendar , largestUnit , untilOptions ) ) ;
4604
4613
( { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = RoundDuration (
0 commit comments