Skip to content

Commit 1b051cc

Browse files
ptomatoMs2ger
authored andcommitted
Rebase: Replace GetEpochFromISOParts with GetUTCEpochNanoseconds
GetEpochFromISOParts was already merged into ECMA-262 and renamed to GetUTCEpochNanoseconds. Its IsValidISODate assertion was removed, so add that in the one place where it isn't redundant.
1 parent 409ab66 commit 1b051cc

File tree

6 files changed

+35
-42
lines changed

6 files changed

+35
-42
lines changed

polyfill/lib/ecmascript.mjs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export const ES = ObjectAssign({}, ES2022, {
519519
microsecond,
520520
nanosecond - offsetNs
521521
));
522-
const epochNs = ES.GetEpochFromISOParts(
522+
const epochNs = ES.GetUTCEpochNanoseconds(
523523
year,
524524
month,
525525
day,
@@ -1247,7 +1247,7 @@ export const ES = ObjectAssign({}, ES2022, {
12471247
// for this timezone and date/time.
12481248
if (offsetBehaviour === 'exact' || offsetOpt === 'use') {
12491249
// Calculate the instant for the input's date/time and offset
1250-
const epochNs = ES.GetEpochFromISOParts(
1250+
const epochNs = ES.GetUTCEpochNanoseconds(
12511251
year,
12521252
month,
12531253
day,
@@ -1785,7 +1785,17 @@ export const ES = ObjectAssign({}, ES2022, {
17851785
const millisecond = GetSlot(dateTime, ISO_MILLISECOND);
17861786
const microsecond = GetSlot(dateTime, ISO_MICROSECOND);
17871787
const nanosecond = GetSlot(dateTime, ISO_NANOSECOND);
1788-
const utcns = ES.GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
1788+
const utcns = ES.GetUTCEpochNanoseconds(
1789+
year,
1790+
month,
1791+
day,
1792+
hour,
1793+
minute,
1794+
second,
1795+
millisecond,
1796+
microsecond,
1797+
nanosecond
1798+
);
17891799
if (utcns === null) throw new RangeError('DateTime outside of supported range');
17901800
const dayBefore = new Instant(utcns.minus(86400e9));
17911801
const dayAfter = new Instant(utcns.plus(86400e9));
@@ -2153,7 +2163,7 @@ export const ES = ObjectAssign({}, ES2022, {
21532163
GetIANATimeZoneOffsetNanoseconds: (epochNanoseconds, id) => {
21542164
const { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } =
21552165
ES.GetIANATimeZoneDateTimeParts(epochNanoseconds, id);
2156-
const utc = ES.GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
2166+
const utc = ES.GetUTCEpochNanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
21572167
if (utc === null) throw new RangeError('Date outside of supported range');
21582168
return +utc.minus(epochNanoseconds);
21592169
},
@@ -2189,7 +2199,7 @@ export const ES = ObjectAssign({}, ES2022, {
21892199
const minuteString = ES.ISODateTimePartString(minutes);
21902200
return `${sign}${hourString}:${minuteString}`;
21912201
},
2192-
GetEpochFromISOParts: (year, month, day, hour, minute, second, millisecond, microsecond, nanosecond) => {
2202+
GetUTCEpochNanoseconds: (year, month, day, hour, minute, second, millisecond, microsecond, nanosecond) => {
21932203
// Note: Date.UTC() interprets one and two-digit years as being in the
21942204
// 20th century, so don't use it
21952205
const legacyDate = new Date();
@@ -2310,7 +2320,7 @@ export const ES = ObjectAssign({}, ES2022, {
23102320
};
23112321
},
23122322
GetIANATimeZoneEpochValue: (id, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond) => {
2313-
let ns = ES.GetEpochFromISOParts(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
2323+
let ns = ES.GetUTCEpochNanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond);
23142324
if (ns === null) throw new RangeError('DateTime outside of supported range');
23152325
let nsEarlier = ns.minus(DAY_NANOS);
23162326
if (nsEarlier.lesser(NS_MIN)) nsEarlier = ns;
@@ -3048,7 +3058,7 @@ export const ES = ObjectAssign({}, ES2022, {
30483058
if (
30493059
(year === YEAR_MIN &&
30503060
null ==
3051-
ES.GetEpochFromISOParts(
3061+
ES.GetUTCEpochNanoseconds(
30523062
year,
30533063
month,
30543064
day + 1,
@@ -3061,7 +3071,17 @@ export const ES = ObjectAssign({}, ES2022, {
30613071
)) ||
30623072
(year === YEAR_MAX &&
30633073
null ==
3064-
ES.GetEpochFromISOParts(year, month, day - 1, hour, minute, second, millisecond, microsecond, nanosecond + 1))
3074+
ES.GetUTCEpochNanoseconds(
3075+
year,
3076+
month,
3077+
day - 1,
3078+
hour,
3079+
minute,
3080+
second,
3081+
millisecond,
3082+
microsecond,
3083+
nanosecond + 1
3084+
))
30653085
) {
30663086
throw new RangeError('DateTime outside of supported range');
30673087
}

polyfill/lib/timezone.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class TimeZone {
8080
const id = GetSlot(this, TIMEZONE_ID);
8181

8282
if (ES.TestTimeZoneOffsetString(id)) {
83-
const epochNs = ES.GetEpochFromISOParts(
83+
const epochNs = ES.GetUTCEpochNanoseconds(
8484
GetSlot(dateTime, ISO_YEAR),
8585
GetSlot(dateTime, ISO_MONTH),
8686
GetSlot(dateTime, ISO_DAY),

spec/instant.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ <h1>ParseTemporalInstant ( _isoString_ )</h1>
522522
1. Let _result_ be ? ParseTemporalInstantString(_isoString_).
523523
1. Let _offsetString_ be _result_.[[TimeZoneOffsetString]].
524524
1. Assert: _offsetString_ is not *undefined*.
525-
1. Let _utc_ be GetEpochFromISOParts(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
525+
1. Let _utc_ be GetUTCEpochNanoseconds(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
526526
1. Let _offsetNanoseconds_ be ? ParseTimeZoneOffsetString(_offsetString_).
527527
1. Let _result_ be _utc_ - ℤ(_offsetNanoseconds_).
528528
1. If ! IsValidEpochNanoseconds(_result_) is *false*, then

spec/plaindatetime.html

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -789,34 +789,6 @@ <h1>Properties of Temporal.PlainDateTime Instances</h1>
789789
<emu-clause id="sec-temporal-plaindatetime-abstract-ops">
790790
<h1>Abstract operations</h1>
791791

792-
<emu-clause id="sec-temporal-getepochfromisoparts" type="abstract operation">
793-
<h1>
794-
GetEpochFromISOParts (
795-
_year_: an integer,
796-
_month_: an integer between 1 and 12 inclusive,
797-
_day_: an integer between 1 and 31 inclusive,
798-
_hour_: an integer between 0 and 23 inclusive,
799-
_minute_: an integer between 0 and 59 inclusive,
800-
_second_: an integer between 0 and 59 inclusive,
801-
_millisecond_: an integer between 0 and 999 inclusive,
802-
_microsecond_: an integer between 0 and 999 inclusive,
803-
_nanosecond_: an integer between 0 and 999 inclusive,
804-
): a BigInt
805-
</h1>
806-
<dl class="header">
807-
<dt>description</dt>
808-
<dd>The returned value represents a number of nanoseconds since the Unix epoch in UTC that corresponds to the given ISO 8601 calendar date and wall-clock time in UTC.</dd>
809-
</dl>
810-
<emu-alg>
811-
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
812-
1. Let _date_ be MakeDay(𝔽(_year_), 𝔽(_month_ - 1), 𝔽(_day_)).
813-
1. Let _time_ be MakeTime(𝔽(_hour_), 𝔽(_minute_), 𝔽(_second_), 𝔽(_millisecond_)).
814-
1. Let _ms_ be MakeDate(_date_, _time_).
815-
1. Assert: _ms_ is finite.
816-
1. Return ℤ(ℝ(_ms_) &times; 10<sup>6</sup> + _microsecond_ &times; 10<sup>3</sup> + _nanosecond_).
817-
</emu-alg>
818-
</emu-clause>
819-
820792
<emu-clause id="sec-temporal-isodatetimewithinlimits" type="abstract operation">
821793
<h1>
822794
ISODateTimeWithinLimits (
@@ -843,7 +815,7 @@ <h1>
843815
</emu-note>
844816
<emu-alg>
845817
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
846-
1. Let _ns_ be ℝ(GetEpochFromISOParts(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_)).
818+
1. Let _ns_ be ℝ(GetUTCEpochNanoseconds(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_)).
847819
1. If _ns_ &le; nsMinInstant - nsPerDay, then
848820
1. Return *false*.
849821
1. If _ns_ &ge; nsMaxInstant + nsPerDay, then

spec/timezone.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ <h1>Temporal.TimeZone.prototype.getPossibleInstantsFor ( _dateTime_ )</h1>
271271
1. Perform ? RequireInternalSlot(_timeZone_, [[InitializedTemporalTimezone]]).
272272
1. Set _dateTime_ to ? ToTemporalDateTime(_dateTime_).
273273
1. If _timeZone_.[[OffsetNanoseconds]] is not *undefined*, then
274-
1. Let _epochNanoseconds_ be GetEpochFromISOParts(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]]).
274+
1. Let _epochNanoseconds_ be GetUTCEpochNanoseconds(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]]).
275275
1. Let _possibleEpochNanoseconds_ be « _epochNanoseconds_ - ℤ(_timeZone_.[[OffsetNanoseconds]]) ».
276276
1. Else,
277277
1. Let _possibleEpochNanoseconds_ be GetIANATimeZoneEpochValue(_timeZone_.[[Identifier]], _dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]]).
@@ -701,7 +701,7 @@ <h1>DisambiguatePossibleInstants ( _possibleInstants_, _timeZone_, _dateTime_, _
701701
1. Assert: _n_ = 0.
702702
1. If _disambiguation_ is *"reject"*, then
703703
1. Throw a *RangeError* exception.
704-
1. Let _epochNanoseconds_ be GetEpochFromISOParts(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]]).
704+
1. Let _epochNanoseconds_ be GetUTCEpochNanoseconds(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]]).
705705
1. Let _dayBeforeNs_ be _epochNanoseconds_ - ℤ(nsPerDay).
706706
1. If ! IsValidEpochNanoseconds(_dayBeforeNs_) is *false*, throw a *RangeError* exception.
707707
1. Let _dayBefore_ be ! CreateTemporalInstant(_dayBeforeNs_).

spec/zoneddatetime.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,14 @@ <h1>
10451045
</dd>
10461046
</dl>
10471047
<emu-alg>
1048+
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
10481049
1. Let _calendar_ be ! GetISO8601Calendar().
10491050
1. Let _dateTime_ be ? CreateTemporalDateTime(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _calendar_).
10501051
1. If _offsetBehaviour_ is ~wall~ or _offsetOption_ is *"ignore"*, then
10511052
1. Let _instant_ be ? BuiltinTimeZoneGetInstantFor(_timeZone_, _dateTime_, _disambiguation_).
10521053
1. Return _instant_.[[Nanoseconds]].
10531054
1. If _offsetBehaviour_ is ~exact~ or _offsetOption_ is *"use"*, then
1054-
1. Let _epochNanoseconds_ be GetEpochFromISOParts(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1055+
1. Let _epochNanoseconds_ be GetUTCEpochNanoseconds(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
10551056
1. Set _epochNanoseconds_ to _epochNanoseconds_ - ℤ(_offsetNanoseconds_).
10561057
1. If ! IsValidEpochNanoseconds(_epochNanoseconds_) is *false*, throw a *RangeError* exception.
10571058
1. Return _epochNanoseconds_.

0 commit comments

Comments
 (0)