Skip to content

Commit aca38be

Browse files
committed
Editorial: Remove ToTemporalDateTimeRoundingIncrement
This operation was already out of sync between the reference code and the spec text because it was called from entirely different places. Remove it altogether, inlining it into all of its call sites both in the spec text and the polyfill.
1 parent fe806fa commit aca38be

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed

polyfill/lib/duration.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SetSlot
1919
} from './slots.mjs';
2020

21+
const MathFloor = Math.floor;
2122
const ObjectCreate = Object.create;
2223

2324
export class Duration {
@@ -255,7 +256,23 @@ export class Duration {
255256
throw new RangeError(`largestUnit ${largestUnit} cannot be smaller than smallestUnit ${smallestUnit}`);
256257
}
257258
const roundingMode = ES.ToTemporalRoundingMode(roundTo, 'halfExpand');
258-
const roundingIncrement = ES.ToTemporalDateTimeRoundingIncrement(roundTo, smallestUnit);
259+
260+
const maximumIncrements = {
261+
hour: 24,
262+
minute: 60,
263+
second: 60,
264+
millisecond: 1000,
265+
microsecond: 1000,
266+
nanosecond: 1000
267+
};
268+
let roundingIncrement = ES.ToTemporalRoundingIncrement(roundTo);
269+
const maximum = maximumIncrements[smallestUnit];
270+
if (maximum == undefined) {
271+
roundingIncrement = MathFloor(roundingIncrement);
272+
} else {
273+
roundingIncrement = ES.ValidateTemporalRoundingIncrement(roundingIncrement, maximum, false);
274+
}
275+
259276
let relativeTo = ES.ToRelativeTemporalObject(roundTo);
260277

261278
({ years, months, weeks, days } = ES.UnbalanceDurationRelative(

polyfill/lib/ecmascript.mjs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -793,24 +793,6 @@ export const ES = ObjectAssign({}, ES2022, {
793793
}
794794
return increment;
795795
},
796-
ToTemporalDateTimeRoundingIncrement: (options, smallestUnit) => {
797-
const maximumIncrements = {
798-
year: undefined,
799-
month: undefined,
800-
week: undefined,
801-
day: undefined,
802-
hour: 24,
803-
minute: 60,
804-
second: 60,
805-
millisecond: 1000,
806-
microsecond: 1000,
807-
nanosecond: 1000
808-
};
809-
const increment = ES.ToTemporalRoundingIncrement(options);
810-
const maximum = maximumIncrements[smallestUnit];
811-
if (maximum == undefined) return MathFloor(increment);
812-
return ES.ValidateTemporalRoundingIncrement(increment, maximum, false);
813-
},
814796
ToSecondsStringPrecision: (options) => {
815797
const smallestUnit = ES.GetTemporalUnit(options, 'smallestUnit', 'time', undefined);
816798
if (smallestUnit === 'hour') {

spec/abstractops.html

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,6 @@ <h1>
243243
</emu-alg>
244244
</emu-clause>
245245

246-
<emu-clause id="sec-temporal-totemporaldatetimeroundingincrement" aoid="ToTemporalDateTimeRoundingIncrement">
247-
<h1>ToTemporalDateTimeRoundingIncrement ( _normalizedOptions_, _smallestUnit_ )</h1>
248-
<p>
249-
The abstract operation ToTemporalDateTimeRoundingIncrement extracts the value of the property named *"roundingIncrement"* from _normalizedOptions_ and makes sure it is a valid value for the option, setting the correct maximum for rounding Temporal.ZonedDateTime and Temporal.PlainDateTime.
250-
</p>
251-
<emu-alg>
252-
1. If _smallestUnit_ is *"day"*, then
253-
1. Let _maximum_ be 1.
254-
1. Else,
255-
1. Let _maximum_ be ! MaximumTemporalDurationRoundingIncrement(_smallestUnit_).
256-
1. Assert: _maximum_ is not *undefined*.
257-
1. Let _increment_ be ? ToTemporalRoundingIncrement(_normalizedOptions_).
258-
1. Return ? ValidateTemporalRoundingIncrement(_increment_, _maximum_, *false*).
259-
</emu-alg>
260-
</emu-clause>
261-
262246
<emu-clause id="sec-temporal-tosecondsstringprecision" aoid="ToSecondsStringPrecision">
263247
<h1>ToSecondsStringPrecision ( _normalizedOptions_ )</h1>
264248
<p>

spec/plaindatetime.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,13 @@ <h1>Temporal.PlainDateTime.prototype.round ( _roundTo_ )</h1>
517517
1. Set _roundTo_ to ? GetOptionsObject(_roundTo_).
518518
1. Let _smallestUnit_ be ? GetTemporalUnit(_roundTo_, *"smallestUnit"*, ~time~, ~required~, « *"day"* »).
519519
1. Let _roundingMode_ be ? ToTemporalRoundingMode(_roundTo_, *"halfExpand"*).
520-
1. Let _roundingIncrement_ be ? ToTemporalDateTimeRoundingIncrement(_roundTo_, _smallestUnit_).
520+
1. If _smallestUnit_ is *"day"*, then
521+
1. Let _maximum_ be 1.
522+
1. Else,
523+
1. Let _maximum_ be ! MaximumTemporalDurationRoundingIncrement(_smallestUnit_).
524+
1. Assert: _maximum_ is not *undefined*.
525+
1. Let _roundingIncrement_ be ? ToTemporalRoundingIncrement(_roundTo_).
526+
1. Set _roundingIncrement_ to ? ValidateTemporalRoundingIncrement(_roundingIncrement_, _maximum_, *false*).
521527
1. Let _result_ be ! RoundISODateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _roundingIncrement_, _smallestUnit_, _roundingMode_).
522528
1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
523529
</emu-alg>

spec/zoneddatetime.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,13 @@ <h1>Temporal.ZonedDateTime.prototype.round ( _roundTo_ )</h1>
735735
1. Set _roundTo_ to ? GetOptionsObject(_roundTo_).
736736
1. Let _smallestUnit_ be ? GetTemporalUnit(_roundTo_, *"smallestUnit"*, ~time~, ~required~, « *"day"* »).
737737
1. Let _roundingMode_ be ? ToTemporalRoundingMode(_roundTo_, *"halfExpand"*).
738-
1. Let _roundingIncrement_ be ? ToTemporalDateTimeRoundingIncrement(_roundTo_, _smallestUnit_).
738+
1. If _smallestUnit_ is *"day"*, then
739+
1. Let _maximum_ be 1.
740+
1. Else,
741+
1. Let _maximum_ be ! MaximumTemporalDurationRoundingIncrement(_smallestUnit_).
742+
1. Assert: _maximum_ is not *undefined*.
743+
1. Let _roundingIncrement_ be ? ToTemporalRoundingIncrement(_roundTo_).
744+
1. Set _roundingIncrement_ to ? ValidateTemporalRoundingIncrement(_roundingIncrement_, _maximum_, *false*).
739745
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
740746
1. Let _instant_ be ! CreateTemporalInstant(_zonedDateTime_.[[Nanoseconds]]).
741747
1. Let _calendar_ be _zonedDateTime_.[[Calendar]].

0 commit comments

Comments
 (0)