@@ -1513,11 +1513,10 @@ export function ToTemporalDuration(item: DurationParams['from'][0]) {
1513
1513
}
1514
1514
1515
1515
export function ToTemporalInstant ( itemParam : InstantParams [ 'from' ] [ 0 ] ) {
1516
- const TemporalInstant = GetIntrinsic ( '%Temporal.Instant%' ) ;
1517
1516
let item : string | number ;
1518
1517
if ( IsObject ( itemParam ) ) {
1519
1518
if ( IsTemporalInstant ( itemParam ) || IsTemporalZonedDateTime ( itemParam ) ) {
1520
- return new TemporalInstant ( GetSlot ( itemParam , EPOCHNANOSECONDS ) ) ;
1519
+ return CreateTemporalInstant ( GetSlot ( itemParam , EPOCHNANOSECONDS ) ) ;
1521
1520
}
1522
1521
item = ToPrimitive ( itemParam , String ) ;
1523
1522
} else {
@@ -1548,8 +1547,7 @@ export function ToTemporalInstant(itemParam: InstantParams['from'][0]) {
1548
1547
) ;
1549
1548
CheckISODaysRange ( balanced . isoDate ) ;
1550
1549
const epochNanoseconds = GetUTCEpochNanoseconds ( balanced ) ;
1551
- ValidateEpochNanoseconds ( epochNanoseconds ) ;
1552
- return new TemporalInstant ( epochNanoseconds ) ;
1550
+ return CreateTemporalInstant ( epochNanoseconds ) ;
1553
1551
}
1554
1552
1555
1553
export function ToTemporalMonthDay ( item : PlainMonthDayParams [ 'from' ] [ 0 ] , options ?: PlainMonthDayParams [ 'from' ] [ 1 ] ) {
@@ -1935,6 +1933,30 @@ export function CreateTemporalYearMonth(isoDate: ISODate, calendar: BuiltinCalen
1935
1933
return result ;
1936
1934
}
1937
1935
1936
+ export function CreateTemporalInstantSlots ( result : Temporal . Instant , epochNanoseconds : JSBI ) {
1937
+ ValidateEpochNanoseconds ( epochNanoseconds ) ;
1938
+ CreateSlots ( result ) ;
1939
+ SetSlot ( result , EPOCHNANOSECONDS , epochNanoseconds ) ;
1940
+
1941
+ if ( DEBUG ) {
1942
+ const iso = GetISOPartsFromEpoch ( epochNanoseconds ) ;
1943
+ const repr = ISODateTimeToString ( iso , 'iso8601' , 'auto' , 'never' ) + 'Z' ;
1944
+ Object . defineProperty ( result , '_repr_' , {
1945
+ value : `${ result [ Symbol . toStringTag ] } <${ repr } >` ,
1946
+ writable : false ,
1947
+ enumerable : false ,
1948
+ configurable : false
1949
+ } ) ;
1950
+ }
1951
+ }
1952
+
1953
+ export function CreateTemporalInstant ( epochNanoseconds : JSBI ) {
1954
+ const TemporalInstant = GetIntrinsic ( '%Temporal.Instant%' ) ;
1955
+ const result : Temporal . Instant = Object . create ( TemporalInstant . prototype ) ;
1956
+ CreateTemporalInstantSlots ( result , epochNanoseconds ) ;
1957
+ return result ;
1958
+ }
1959
+
1938
1960
export function CreateTemporalZonedDateTimeSlots (
1939
1961
result : Temporal . ZonedDateTime ,
1940
1962
epochNanoseconds : JSBI ,
@@ -2684,7 +2706,7 @@ function GetUTCEpochNanoseconds(isoDateTime: ISODateTime) {
2684
2706
return JSBI . add ( epochMsToNs ( ms ) , JSBI . BigInt ( subMs ) ) ;
2685
2707
}
2686
2708
2687
- export function GetISOPartsFromEpoch ( epochNanoseconds : JSBI ) {
2709
+ function GetISOPartsFromEpoch ( epochNanoseconds : JSBI ) {
2688
2710
let epochMilliseconds = epochNsToMs ( epochNanoseconds , 'trunc' ) ;
2689
2711
let nanos = JSBI . toNumber ( JSBI . remainder ( epochNanoseconds , MILLION ) ) ;
2690
2712
if ( nanos < 0 ) {
@@ -3196,7 +3218,7 @@ function AssertISODateTimeWithinLimits(isoDateTime: ISODateTime) {
3196
3218
// In the spec, IsValidEpochNanoseconds returns a boolean and call sites are
3197
3219
// responsible for throwing. In the polyfill, ValidateEpochNanoseconds takes its
3198
3220
// place so that we can DRY the throwing code.
3199
- export function ValidateEpochNanoseconds ( epochNanoseconds : JSBI ) {
3221
+ function ValidateEpochNanoseconds ( epochNanoseconds : JSBI ) {
3200
3222
if ( JSBI . lessThan ( epochNanoseconds , NS_MIN ) || JSBI . greaterThan ( epochNanoseconds , NS_MAX ) ) {
3201
3223
throw new RangeError ( 'date/time value is outside of supported range' ) ;
3202
3224
}
@@ -4455,8 +4477,7 @@ export function AddDurationToInstant(
4455
4477
}
4456
4478
const internalDuration = ToInternalDurationRecordWith24HourDays ( duration ) ;
4457
4479
const ns = AddInstant ( GetSlot ( instant , EPOCHNANOSECONDS ) , internalDuration . time ) ;
4458
- const Instant = GetIntrinsic ( '%Temporal.Instant%' ) ;
4459
- return new Instant ( ns ) ;
4480
+ return CreateTemporalInstant ( ns ) ;
4460
4481
}
4461
4482
4462
4483
export function AddDurationToDate (
0 commit comments