Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: Fewer GetOffsetNanosecondsFor calls during InterpretISODateTimeOffset (prefer/reject) #2789

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,9 +1494,20 @@ export function InterpretISODateTimeOffset(
// "prefer" or "reject"
const possibleEpochNs = GetPossibleEpochNanoseconds(timeZone, dt);
if (possibleEpochNs.length > 0) {
const utcEpochNs = GetUTCEpochNanoseconds(
year,
month,
day,
time.hour,
time.minute,
time.second,
time.millisecond,
time.microsecond,
time.nanosecond
);
for (let index = 0; index < possibleEpochNs.length; index++) {
const candidate = possibleEpochNs[index];
const candidateOffset = GetOffsetNanosecondsFor(timeZone, candidate);
const candidateOffset = utcEpochNs - candidate;
const roundedCandidateOffset = RoundNumberToIncrement(candidateOffset, 60e9, 'halfExpand');
if (candidateOffset === offsetNs || (matchMinute && roundedCandidateOffset === offsetNs)) {
return candidate;
Expand Down
3 changes: 2 additions & 1 deletion spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,9 @@ <h1>
1. Assert: _offsetOption_ is *"prefer"* or *"reject"*.
1. Let _possibleEpochNs_ be ? GetPossibleEpochNanoseconds(_timeZone_, _isoDateTime_).
1. If _possibleEpochNs_ is not empty, then
1. Let _utcEpochNanoseconds_ be GetUTCEpochNanoseconds(_year_, _month_, _day_, _time_.[[Hour]], _time_.[[Minute]], _time_.[[Second]], _time_.[[Millisecond]], _time_.[[Microsecond]], _time_.[[Nanosecond]]).
1. For each element _candidate_ of _possibleEpochNs_, do
1. Let _candidateOffset_ be GetOffsetNanosecondsFor(_timeZone_, _candidate_).
1. Let _candidateOffset_ be _utcEpochNanoseconds_ - _candidate_.
1. If _candidateOffset_ = _offsetNanoseconds_, then
1. Return _candidate_.
1. If _matchBehaviour_ is ~match-minutes~, then
Expand Down
Loading