@@ -2762,6 +2762,15 @@ export function RejectDateTimeRange(isoDateTime) {
2762
2762
}
2763
2763
}
2764
2764
2765
+ // Same as above, but throws a different, non-user-facing error
2766
+ function AssertISODateTimeWithinLimits ( isoDateTime ) {
2767
+ const ns = GetUTCEpochNanoseconds ( isoDateTime ) ;
2768
+ assert (
2769
+ ns . geq ( DATETIME_NS_MIN ) && ns . leq ( DATETIME_NS_MAX ) ,
2770
+ `${ ISODateTimeToString ( isoDateTime ) } is outside the representable range`
2771
+ ) ;
2772
+ }
2773
+
2765
2774
// In the spec, IsValidEpochNanoseconds returns a boolean and call sites are
2766
2775
// responsible for throwing. In the polyfill, ValidateEpochNanoseconds takes its
2767
2776
// place so that we can DRY the throwing code.
@@ -3000,6 +3009,8 @@ function DifferenceInstant(ns1, ns2, increment, smallestUnit, roundingMode) {
3000
3009
}
3001
3010
3002
3011
function DifferenceISODateTime ( isoDateTime1 , isoDateTime2 , calendar , largestUnit ) {
3012
+ AssertISODateTimeWithinLimits ( isoDateTime1 ) ;
3013
+ AssertISODateTimeWithinLimits ( isoDateTime2 ) ;
3003
3014
let timeDuration = DifferenceTime ( isoDateTime1 . time , isoDateTime2 . time ) ;
3004
3015
3005
3016
const timeSign = timeDuration . sign ( ) ;
@@ -4006,13 +4017,12 @@ export function RoundTemporalInstant(epochNs, increment, unit, roundingMode) {
4006
4017
return RoundNumberToIncrementAsIfPositive ( epochNs , incrementNs , roundingMode ) ;
4007
4018
}
4008
4019
4009
- export function RoundISODateTime (
4010
- { isoDate : { year, month, day } , time : { hour, minute, second, millisecond, microsecond, nanosecond } } ,
4011
- increment ,
4012
- unit ,
4013
- roundingMode
4014
- ) {
4015
- const time = RoundTime ( { hour, minute, second, millisecond, microsecond, nanosecond } , increment , unit , roundingMode ) ;
4020
+ export function RoundISODateTime ( isoDateTime , increment , unit , roundingMode ) {
4021
+ AssertISODateTimeWithinLimits ( isoDateTime ) ;
4022
+ const {
4023
+ isoDate : { year, month, day }
4024
+ } = isoDateTime ;
4025
+ const time = RoundTime ( isoDateTime . time , increment , unit , roundingMode ) ;
4016
4026
const isoDate = BalanceISODate ( year , month , day + time . deltaDays ) ;
4017
4027
return CombineISODateAndTimeRecord ( isoDate , time ) ;
4018
4028
}
0 commit comments