Skip to content

Commit 4405f30

Browse files
committed
Editorial: Rename Normalized Time Duration to time duration
A normalized time duration is just a number of nanoseconds; we originally planned to convert it to a record with a seconds and subseconds field, but that was never needed. So we don't need to have it be a record in the first place. Rename it to "time duration" (removing "normalized" for the same reason as in the previous commits) and define it as an integer within a certain range. Renames: - all of the NormalizedTimeDuration___ operations to just TimeDuration___ - NormalizeTimeDuration to TimeDurationFromComponents - Internal duration [[NormalizedTime]] field to [[Time]] - "norm" variables to "timeDuration" or "time" if clear from context See: #2953
1 parent ff968bd commit 4405f30

13 files changed

+287
-310
lines changed

polyfill/lib/duration.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class Duration {
252252

253253
if (plainRelativeTo) {
254254
let duration = ES.ToInternalDurationRecordWith24HourDays(this);
255-
const targetTime = ES.AddTime(ES.MidnightTimeRecord(), duration.norm);
255+
const targetTime = ES.AddTime(ES.MidnightTimeRecord(), duration.time);
256256

257257
// Delegate the date part addition to the calendar
258258
const isoRelativeToDate = GetSlot(plainRelativeTo, ISO_DATE);
@@ -311,7 +311,7 @@ export class Duration {
311311

312312
if (plainRelativeTo) {
313313
const duration = ES.ToInternalDurationRecordWith24HourDays(this);
314-
let targetTime = ES.AddTime(ES.MidnightTimeRecord(), duration.norm);
314+
let targetTime = ES.AddTime(ES.MidnightTimeRecord(), duration.time);
315315

316316
// Delegate the date part addition to the calendar
317317
const isoRelativeToDate = GetSlot(plainRelativeTo, ISO_DATE);
@@ -333,7 +333,7 @@ export class Duration {
333333
throw new RangeErrorCtor(`a starting point is required for ${unit}s total`);
334334
}
335335
const duration = ES.ToInternalDurationRecordWith24HourDays(this);
336-
return ES.TotalTimeDuration(duration.norm, unit);
336+
return ES.TotalTimeDuration(duration.time, unit);
337337
}
338338
toString(options = undefined) {
339339
if (!ES.IsTemporalDuration(this)) throw new TypeErrorCtor('invalid receiver');
@@ -423,9 +423,9 @@ export class Duration {
423423
d1 = ES.DateDurationDays(duration1.date, plainRelativeTo);
424424
d2 = ES.DateDurationDays(duration2.date, plainRelativeTo);
425425
}
426-
const norm1 = duration1.norm.add24HourDays(d1);
427-
const norm2 = duration2.norm.add24HourDays(d2);
428-
return norm1.cmp(norm2);
426+
const timeDuration1 = duration1.time.add24HourDays(d1);
427+
const timeDuration2 = duration2.time.add24HourDays(d2);
428+
return timeDuration1.cmp(timeDuration2);
429429
}
430430
}
431431

polyfill/lib/ecmascript.mjs

Lines changed: 72 additions & 72 deletions
Large diffs are not rendered by default.

polyfill/lib/math.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function GetUnsignedRoundingMode(mode, sign) {
8181
}
8282

8383
// Omits first step from spec algorithm so that it can be used both for
84-
// RoundNumberToIncrement and RoundNormalizedTimeDurationToIncrement
84+
// RoundNumberToIncrement and RoundTimeDurationToIncrement
8585
export function ApplyUnsignedRoundingMode(r1, r2, cmp, evenCardinality, unsignedRoundingMode) {
8686
if (unsignedRoundingMode === 'zero') return r1;
8787
if (unsignedRoundingMode === 'infinity') return r2;

polyfill/lib/timeduration.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class TimeDuration {
5050
return new TimeDuration(diff);
5151
}
5252

53-
static normalize(h, min, s, ms, µs, ns) {
53+
static fromComponents(h, min, s, ms, µs, ns) {
5454
const totalNs = bigInt(ns)
5555
.add(bigInt(µs).multiply(1e3))
5656
.add(bigInt(ms).multiply(1e6))

polyfill/test/timeduration.mjs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,40 @@ describe('Normalized time duration', () => {
8282
});
8383
});
8484

85-
describe('normalize()', () => {
85+
describe('fromComponents()', () => {
8686
it('basic', () => {
87-
check(TimeDuration.normalize(1, 1, 1, 1, 1, 1), 3661, 1001001);
88-
check(TimeDuration.normalize(-1, -1, -1, -1, -1, -1), -3661, -1001001);
87+
check(TimeDuration.fromComponents(1, 1, 1, 1, 1, 1), 3661, 1001001);
88+
check(TimeDuration.fromComponents(-1, -1, -1, -1, -1, -1), -3661, -1001001);
8989
});
9090

9191
it('overflow from one unit to another', () => {
92-
check(TimeDuration.normalize(1, 61, 61, 998, 1000, 1000), 7321, 999001000);
93-
check(TimeDuration.normalize(-1, -61, -61, -998, -1000, -1000), -7321, -999001000);
92+
check(TimeDuration.fromComponents(1, 61, 61, 998, 1000, 1000), 7321, 999001000);
93+
check(TimeDuration.fromComponents(-1, -61, -61, -998, -1000, -1000), -7321, -999001000);
9494
});
9595

9696
it('overflow from subseconds to seconds', () => {
97-
check(TimeDuration.normalize(0, 0, 1, 1000, 0, 0), 2, 0);
98-
check(TimeDuration.normalize(0, 0, -1, -1000, 0, 0), -2, 0);
97+
check(TimeDuration.fromComponents(0, 0, 1, 1000, 0, 0), 2, 0);
98+
check(TimeDuration.fromComponents(0, 0, -1, -1000, 0, 0), -2, 0);
9999
});
100100

101101
it('multiple overflows from subseconds to seconds', () => {
102-
check(TimeDuration.normalize(0, 0, 0, 1234567890, 1234567890, 1234567890), 1235803, 692457890);
103-
check(TimeDuration.normalize(0, 0, 0, -1234567890, -1234567890, -1234567890), -1235803, -692457890);
102+
check(TimeDuration.fromComponents(0, 0, 0, 1234567890, 1234567890, 1234567890), 1235803, 692457890);
103+
check(TimeDuration.fromComponents(0, 0, 0, -1234567890, -1234567890, -1234567890), -1235803, -692457890);
104104
});
105105

106106
it('fails on overflow', () => {
107-
throws(() => TimeDuration.normalize(2501999792984, 0, 0, 0, 0, 0), RangeError);
108-
throws(() => TimeDuration.normalize(-2501999792984, 0, 0, 0, 0, 0), RangeError);
109-
throws(() => TimeDuration.normalize(0, 150119987579017, 0, 0, 0, 0), RangeError);
110-
throws(() => TimeDuration.normalize(0, -150119987579017, 0, 0, 0, 0), RangeError);
111-
throws(() => TimeDuration.normalize(0, 0, 2 ** 53, 0, 0, 0), RangeError);
112-
throws(() => TimeDuration.normalize(0, 0, -(2 ** 53), 0, 0, 0), RangeError);
113-
throws(() => TimeDuration.normalize(0, 0, Number.MAX_SAFE_INTEGER, 1000, 0, 0), RangeError);
114-
throws(() => TimeDuration.normalize(0, 0, -Number.MAX_SAFE_INTEGER, -1000, 0, 0), RangeError);
115-
throws(() => TimeDuration.normalize(0, 0, Number.MAX_SAFE_INTEGER, 0, 1000000, 0), RangeError);
116-
throws(() => TimeDuration.normalize(0, 0, -Number.MAX_SAFE_INTEGER, 0, -1000000, 0), RangeError);
117-
throws(() => TimeDuration.normalize(0, 0, Number.MAX_SAFE_INTEGER, 0, 0, 1000000000), RangeError);
118-
throws(() => TimeDuration.normalize(0, 0, -Number.MAX_SAFE_INTEGER, 0, 0, -1000000000), RangeError);
107+
throws(() => TimeDuration.fromComponents(2501999792984, 0, 0, 0, 0, 0), RangeError);
108+
throws(() => TimeDuration.fromComponents(-2501999792984, 0, 0, 0, 0, 0), RangeError);
109+
throws(() => TimeDuration.fromComponents(0, 150119987579017, 0, 0, 0, 0), RangeError);
110+
throws(() => TimeDuration.fromComponents(0, -150119987579017, 0, 0, 0, 0), RangeError);
111+
throws(() => TimeDuration.fromComponents(0, 0, 2 ** 53, 0, 0, 0), RangeError);
112+
throws(() => TimeDuration.fromComponents(0, 0, -(2 ** 53), 0, 0, 0), RangeError);
113+
throws(() => TimeDuration.fromComponents(0, 0, Number.MAX_SAFE_INTEGER, 1000, 0, 0), RangeError);
114+
throws(() => TimeDuration.fromComponents(0, 0, -Number.MAX_SAFE_INTEGER, -1000, 0, 0), RangeError);
115+
throws(() => TimeDuration.fromComponents(0, 0, Number.MAX_SAFE_INTEGER, 0, 1000000, 0), RangeError);
116+
throws(() => TimeDuration.fromComponents(0, 0, -Number.MAX_SAFE_INTEGER, 0, -1000000, 0), RangeError);
117+
throws(() => TimeDuration.fromComponents(0, 0, Number.MAX_SAFE_INTEGER, 0, 0, 1000000000), RangeError);
118+
throws(() => TimeDuration.fromComponents(0, 0, -Number.MAX_SAFE_INTEGER, 0, 0, -1000000000), RangeError);
119119
});
120120
});
121121

@@ -343,7 +343,7 @@ describe('Normalized time duration', () => {
343343
});
344344

345345
it('quotient larger than seconds', () => {
346-
const d = TimeDuration.normalize(25 + 5 * 24, 0, 86401, 333, 666, 999);
346+
const d = TimeDuration.fromComponents(25 + 5 * 24, 0, 86401, 333, 666, 999);
347347
const { quotient, remainder } = d.divmod(86400e9);
348348
equal(quotient, 7);
349349
check(remainder, 3601, 333666999);
@@ -401,7 +401,7 @@ describe('Normalized time duration', () => {
401401
});
402402

403403
it('quotient larger than seconds', () => {
404-
const d = TimeDuration.normalize(25 + 5 * 24, 0, 86401, 333, 666, 999);
404+
const d = TimeDuration.fromComponents(25 + 5 * 24, 0, 86401, 333, 666, 999);
405405
checkFloat(d.fdiv(86400e9), 7.041682102627303);
406406
});
407407

0 commit comments

Comments
 (0)