A Temporal.Instant object is an Object referencing a fixed point in time with nanoseconds precision.
Properties of the Temporal.Instant Constructor
The value of the [[Prototype]] internal slot of the Temporal.Instant constructor is the intrinsic object %Function.prototype%.
The Temporal.Instant constructor has the following properties:
Temporal.Instant.prototype
The initial value of `Temporal.Instant.prototype` is %Temporal.Instant.prototype%.
This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.
Temporal.Instant.from ( _item_ )
This function performs the following steps when called:
1. Return ? ToTemporalInstant(_item_).
Temporal.Instant.fromEpochMilliseconds ( _epochMilliseconds_ )
This function performs the following steps when called:
1. Set _epochMilliseconds_ to ? ToNumber(_epochMilliseconds_).
1. Set _epochMilliseconds_ to ? NumberToBigInt(_epochMilliseconds_).
1. Let _epochNanoseconds_ be _epochMilliseconds_ × ℤ(106).
1. If IsValidEpochNanoseconds(_epochNanoseconds_) is *false*, throw a *RangeError* exception.
1. Return ! CreateTemporalInstant(_epochNanoseconds_).
Temporal.Instant.fromEpochNanoseconds ( _epochNanoseconds_ )
This function performs the following steps when called:
1. Set _epochNanoseconds_ to ? ToBigInt(_epochNanoseconds_).
1. If IsValidEpochNanoseconds(_epochNanoseconds_) is *false*, throw a *RangeError* exception.
1. Return ! CreateTemporalInstant(_epochNanoseconds_).
Temporal.Instant.compare ( _one_, _two_ )
This function performs the following steps when called:
1. Set _one_ to ? ToTemporalInstant(_one_).
1. Set _two_ to ? ToTemporalInstant(_two_).
1. Return 𝔽(CompareEpochNanoseconds(_one_.[[EpochNanoseconds]], _two_.[[EpochNanoseconds]])).
Properties of the Temporal.Instant Prototype Object
The Temporal.Instant prototype object
- is itself an ordinary object.
- is not a Temporal.Instant instance and does not have a [[InitializedTemporalInstant]] internal slot.
- has a [[Prototype]] internal slot whose value is %Object.prototype%.
Temporal.Instant.prototype.constructor
The initial value of `Temporal.Instant.prototype.constructor` is %Temporal.Instant%.
Temporal.Instant.prototype[ %Symbol.toStringTag% ]
The initial value of the %Symbol.toStringTag% property is the String value *"Temporal.Instant"*.
This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.
get Temporal.Instant.prototype.epochMilliseconds
`Temporal.Instant.prototype.epochMilliseconds` is an accessor property whose set accessor function is *undefined*.
Its get accessor function performs the following steps:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Let _ns_ be _instant_.[[EpochNanoseconds]].
1. Let _ms_ be floor(ℝ(_ns_) / 106).
1. Return 𝔽(_ms_).
get Temporal.Instant.prototype.epochNanoseconds
`Temporal.Instant.prototype.epochNanoseconds` is an accessor property whose set accessor function is *undefined*.
Its get accessor function performs the following steps:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return _instant_.[[EpochNanoseconds]].
Temporal.Instant.prototype.add ( _temporalDurationLike_ )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return ? AddDurationToInstant(~add~, _instant_, _temporalDurationLike_).
Temporal.Instant.prototype.subtract ( _temporalDurationLike_ )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return ? AddDurationToInstant(~subtract~, _instant_, _temporalDurationLike_).
Temporal.Instant.prototype.until ( _other_ [ , _options_ ] )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return ? DifferenceTemporalInstant(~until~, _instant_, _other_, _options_).
Temporal.Instant.prototype.since ( _other_ [ , _options_ ] )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return ? DifferenceTemporalInstant(~since~, _instant_, _other_, _options_).
Temporal.Instant.prototype.round ( _roundTo_ )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. If _roundTo_ is *undefined*, then
1. Throw a *TypeError* exception.
1. If _roundTo_ is a String, then
1. Let _paramString_ be _roundTo_.
1. Set _roundTo_ to OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_roundTo_, *"smallestUnit"*, _paramString_).
1. Else,
1. Set _roundTo_ to ? GetOptionsObject(_roundTo_).
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetRoundingIncrementOption reads *"roundingIncrement"* and GetRoundingModeOption reads *"roundingMode"*).
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_roundTo_).
1. Let _roundingMode_ be ? GetRoundingModeOption(_roundTo_, ~half-expand~).
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~time~, ~required~).
1. If _smallestUnit_ is ~hour~, then
1. Let _maximum_ be HoursPerDay.
1. Else if _smallestUnit_ is ~minute~, then
1. Let _maximum_ be MinutesPerHour × HoursPerDay.
1. Else if _smallestUnit_ is ~second~, then
1. Let _maximum_ be SecondsPerMinute × MinutesPerHour × HoursPerDay.
1. Else if _smallestUnit_ is ~millisecond~, then
1. Let _maximum_ be ℝ(msPerDay).
1. Else if _smallestUnit_ is ~microsecond~, then
1. Let _maximum_ be 103 × ℝ(msPerDay).
1. Else,
1. Assert: _smallestUnit_ is ~nanosecond~.
1. Let _maximum_ be nsPerDay.
1. Perform ? ValidateTemporalRoundingIncrement(_roundingIncrement_, _maximum_, *true*).
1. Let _roundedNs_ be RoundTemporalInstant(_instant_.[[EpochNanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_).
1. Return ! CreateTemporalInstant(_roundedNs_).
Temporal.Instant.prototype.equals ( _other_ )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Set _other_ to ? ToTemporalInstant(_other_).
1. If _instant_.[[EpochNanoseconds]] ≠ _other_.[[EpochNanoseconds]], return *false*.
1. Return *true*.
Temporal.Instant.prototype.toString ( [ _options_ ] )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Let _resolvedOptions_ be ? GetOptionsObject(_options_).
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetTemporalFractionalSecondDigitsOption reads *"fractionalSecondDigits"* and GetRoundingModeOption reads *"roundingMode"*).
1. Let _digits_ be ? GetTemporalFractionalSecondDigitsOption(_resolvedOptions_).
1. Let _roundingMode_ be ? GetRoundingModeOption(_resolvedOptions_, ~trunc~).
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~time~, ~unset~).
1. If _smallestUnit_ is ~hour~, throw a *RangeError* exception.
1. Let _timeZone_ be ? Get(_resolvedOptions_, *"timeZone"*).
1. If _timeZone_ is not *undefined*, then
1. Set _timeZone_ to ? ToTemporalTimeZoneIdentifier(_timeZone_).
1. Let _precision_ be ToSecondsStringPrecisionRecord(_smallestUnit_, _digits_).
1. Let _roundedNs_ be RoundTemporalInstant(_instant_.[[EpochNanoseconds]], _precision_.[[Increment]], _precision_.[[Unit]], _roundingMode_).
1. Let _roundedInstant_ be ! CreateTemporalInstant(_roundedNs_).
1. Return TemporalInstantToString(_roundedInstant_, _timeZone_, _precision_.[[Precision]]).
Temporal.Instant.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification.
If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.
The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else.
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return TemporalInstantToString(_instant_, *undefined*, ~auto~).
Temporal.Instant.prototype.toJSON ( )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Return TemporalInstantToString(_instant_, *undefined*, ~auto~).
Temporal.Instant.prototype.valueOf ( )
This method performs the following steps when called:
1. Throw a *TypeError* exception.
This method always throws, because in the absence of `valueOf()`, expressions with arithmetic operators such as `instant1 > instant2` would fall back to being equivalent to `instant1.toString() > instant2.toString()`.
Lexicographical comparison of serialized strings might not seem obviously wrong, because the result would sometimes be correct.
Implementations are encouraged to phrase the error message to point users to `Temporal.Instant.compare()`, `Temporal.Instant.prototype.equals()`, and/or `Temporal.Instant.prototype.toString()`.
Temporal.Instant.prototype.toZonedDateTimeISO ( _timeZone_ )
This method performs the following steps when called:
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Set _timeZone_ to ? ToTemporalTimeZoneIdentifier(_timeZone_).
1. Return ! CreateTemporalZonedDateTime(_instant_.[[EpochNanoseconds]], _timeZone_, *"iso8601"*).
Properties of Temporal.Instant Instances
Temporal.Instant instances are ordinary objects that inherit properties from the %Temporal.Instant.prototype% intrinsic object.
Temporal.Instant instances are initially created with the internal slots described in .
|
Internal Slot
|
Description
|
|
[[InitializedTemporalInstant]]
|
The only specified use of this slot is for distinguishing Temporal.Instant instances from other objects.
|
|
[[EpochNanoseconds]]
|
A BigInt value representing the number of nanoseconds since the epoch.
|
Temporal.Instant range
The [[EpochNanoseconds]] internal slot of a Temporal.Instant object supports a range of exactly -100,000,000 to 100,000,000 days relative to midnight at the beginning of 1 January 1970 UTC, as in .
The exact moment of midnight at the beginning of 1 January 1970 UTC is represented by the value *0*ℤ.
The maximum value is ℤ(nsMaxInstant), where
nsMaxInstant = 108 × nsPerDay = 8.64 × 1021
where the number of nanoseconds per day is
nsPerDay = 106 × ℝ(msPerDay) = 8.64 × 1013
The minimum value is ℤ(nsMinInstant), where
nsMinInstant = -nsMaxInstant = -8.64 × 1021