Skip to content

Commit

Permalink
Editorial?: Use normalized time duration in operations
Browse files Browse the repository at this point in the history
This introduces Normalized Time Duration Records, which we use to
encapsulate 96-bit integer operations on duration times. (In the reference
polyfill, the TimeDuration class fulfills the same purpose.) These
operations are specified naively in the mathematical value domain, but can
be changed in a later editorial commit to correspond to how
implementations would write 64+32 bit operations, if we so desire. (The
results must be exactly the same, so that can be decided later, outside of
a TC39 plenary.)

This commit also replaces TotalDurationNanoseconds with
NormalizeTimeDuration, and NanosecondsToDays with
NormalizedTimeDurationToDays. Several operations are changed to return a
Normalized Duration Record, which is a Normalized Time Duration record
combined with a Date Duration Record.

Having already limited time units of durations in the previous commit,
this does not affect any results, nor any existing tests in test262. But I
can't prove conclusively that there isn't some edge case somewhere that
makes this change observable.

(also obsoletes several pre-existing editorial mistakes)
Closes: #2536
Closes: #2638
Closes: #2616
  • Loading branch information
ptomato committed Jan 31, 2024
1 parent 45462c4 commit 7b924d4
Show file tree
Hide file tree
Showing 20 changed files with 1,801 additions and 1,046 deletions.
8 changes: 4 additions & 4 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
HasSlot,
SetSlot
} from './slots.mjs';
import { TimeDuration } from './timeduration.mjs';

const ArrayFrom = Array.from;
const ArrayIncludes = Array.prototype.includes;
Expand Down Expand Up @@ -157,16 +158,15 @@ export class Calendar {
duration = ES.ToTemporalDuration(duration);
options = ES.GetOptionsObject(options);
const overflow = ES.ToTemporalOverflow(options);
const { days } = ES.BalanceTimeDuration(
GetSlot(duration, DAYS),
const norm = TimeDuration.normalize(
GetSlot(duration, HOURS),
GetSlot(duration, MINUTES),
GetSlot(duration, SECONDS),
GetSlot(duration, MILLISECONDS),
GetSlot(duration, MICROSECONDS),
GetSlot(duration, NANOSECONDS),
'day'
GetSlot(duration, NANOSECONDS)
);
const days = GetSlot(duration, DAYS) + ES.BalanceTimeDuration(norm, 'day').days;
const id = GetSlot(this, CALENDAR_ID);
return impl[id].dateAdd(
date,
Expand Down
Loading

0 comments on commit 7b924d4

Please sign in to comment.