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: Small batch of editorial issues #2928

Merged
merged 3 commits into from
Aug 21, 2024
Merged
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
19 changes: 2 additions & 17 deletions polyfill/lib/duration.mjs
Original file line number Diff line number Diff line change
@@ -160,23 +160,8 @@ export class Duration {
}
with(durationLike) {
if (!ES.IsTemporalDuration(this)) throw new TypeError('invalid receiver');
const partialDuration = ES.PrepareTemporalFields(
durationLike,
[
'days',
'hours',
'microseconds',
'milliseconds',
'minutes',
'months',
'nanoseconds',
'seconds',
'weeks',
'years'
],
'partial'
);
let {
const partialDuration = ES.ToTemporalPartialDurationRecord(durationLike);
const {
years = GetSlot(this, YEARS),
months = GetSlot(this, MONTHS),
weeks = GetSlot(this, WEEKS),
42 changes: 16 additions & 26 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ const NumberMaxSafeInteger = Number.MAX_SAFE_INTEGER;
const ObjectCreate = Object.create;
const ObjectDefineProperty = Object.defineProperty;
const ObjectEntries = Object.entries;
const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
const SetPrototypeHas = Set.prototype.has;
const StringCtor = String;
const StringFromCharCode = String.fromCharCode;
@@ -229,16 +228,6 @@ const BUILTIN_CASTS = new Map([
['millisecond', ToIntegerWithTruncation],
['microsecond', ToIntegerWithTruncation],
['nanosecond', ToIntegerWithTruncation],
['years', ToIntegerIfIntegral],
['months', ToIntegerIfIntegral],
['weeks', ToIntegerIfIntegral],
['days', ToIntegerIfIntegral],
['hours', ToIntegerIfIntegral],
['minutes', ToIntegerIfIntegral],
['seconds', ToIntegerIfIntegral],
['milliseconds', ToIntegerIfIntegral],
['microseconds', ToIntegerIfIntegral],
['nanoseconds', ToIntegerIfIntegral],
['offset', ToPrimitiveAndRequireString]
]);

@@ -1146,8 +1135,7 @@ export function PrepareTemporalFields(
fields,
requiredFields,
extraFieldDescriptors = [],
duplicateBehaviour = 'throw',
{ emptySourceErrorMessage = 'no supported properties found' } = {}
duplicateBehaviour = 'throw'
) {
const result = ObjectCreate(null);
let any = false;
@@ -1196,7 +1184,7 @@ export function PrepareTemporalFields(
previousProperty = property;
}
if (requiredFields === 'partial' && !any) {
throw new TypeError(emptySourceErrorMessage);
throw new TypeError('no supported properties found');
}
return result;
}
@@ -1242,19 +1230,19 @@ export function PrepareCalendarFields(calendarRec, bag, calendarFieldNames, nonC

export function ToTemporalTimeRecord(bag, completeness = 'complete') {
const fields = ['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'second'];
const partial = PrepareTemporalFields(bag, fields, 'partial', undefined, undefined, {
emptySourceErrorMessage: 'invalid time-like'
});
const result = {};
let any = false;
const result = ObjectCreate(null);
for (let index = 0; index < fields.length; index++) {
const field = fields[index];
const valueDesc = ObjectGetOwnPropertyDescriptor(partial, field);
if (valueDesc !== undefined) {
result[field] = valueDesc.value;
const value = bag[field];
if (value !== undefined) {
result[field] = ToIntegerWithTruncation(value);
any = true;
} else if (completeness === 'complete') {
result[field] = 0;
}
}
if (!any) throw new TypeError('invalid time-like');
return result;
}

@@ -5388,15 +5376,17 @@ export function RoundTime(hour, minute, second, millisecond, microsecond, nanose
}

export function DaysUntil(earlier, later) {
return DifferenceISODate(
const epochDaysEarlier = ISODateToEpochDays(
GetSlot(earlier, ISO_YEAR),
GetSlot(earlier, ISO_MONTH),
GetSlot(earlier, ISO_DAY),
GetSlot(earlier, ISO_DAY)
);
const epochDaysLater = ISODateToEpochDays(
GetSlot(later, ISO_YEAR),
GetSlot(later, ISO_MONTH),
GetSlot(later, ISO_DAY),
'day'
).days;
GetSlot(later, ISO_DAY)
);
return epochDaysLater - epochDaysEarlier;
}

export function RoundTimeDuration(days, norm, increment, unit, roundingMode) {
6 changes: 3 additions & 3 deletions spec/duration.html
Original file line number Diff line number Diff line change
@@ -1719,9 +1719,9 @@ <h1>
If _earlier_ is later than _later_, then the result is negative.</dd>
</dl>
<emu-alg>
1. Let _epochDays1_ be ISODateToEpochDays(_earlier_.[[ISOYear]], _earlier_.[[ISOMonth]] - 1, _earlier_.[[ISODay]]).
1. Let _epochDays2_ be ISODateToEpochDays(_later_.[[ISOYear]], _later_.[[ISOMonth]] - 1, _later_.[[ISODay]]).
1. Return _epochDays2_ - _epochDays1_.
1. Let _epochDaysEarlier_ be ISODateToEpochDays(_earlier_.[[ISOYear]], _earlier_.[[ISOMonth]] - 1, _earlier_.[[ISODay]]).
1. Let _epochDaysLater_ be ISODateToEpochDays(_later_.[[ISOYear]], _later_.[[ISOMonth]] - 1, _later_.[[ISODay]]).
1. Return _epochDaysLater_ - _epochDaysEarlier_.
</emu-alg>
</emu-clause>

53 changes: 27 additions & 26 deletions spec/plaintime.html
Original file line number Diff line number Diff line change
@@ -816,35 +816,36 @@ <h1>
</dl>
<emu-alg>
1. If _completeness_ is not present, set _completeness_ to ~complete~.
1. Let _partial_ be ? PrepareTemporalFields(_temporalTimeLike_, « *"hour"*, *"microsecond"*, *"millisecond"*, *"minute"*, *"nanosecond"*, *"second"* », ~partial~).
1. If _completeness_ is ~complete~, then
1. Let _result_ be a new TemporalTimeLike Record with each field set to 0.
1. Else,
1. Let _result_ be a new TemporalTimeLike Record with each field set to *undefined*.
1. Let _hourDesc_ be OrdinaryGetOwnProperty(_partial_, *"hour"*).
1. If _hourDesc_ is not *undefined*, then
1. Assert: _hourDesc_ is a data Property Descriptor.
1. Set _result_.[[Hour]] to ℝ(_hourDesc_.[[Value]]).
1. Let _minuteDesc_ be OrdinaryGetOwnProperty(_partial_, *"minute"*).
1. If _minuteDesc_ is not *undefined*, then
1. Assert: _minuteDesc_ is a data Property Descriptor.
1. Set _result_.[[Minute]] to ℝ(_minuteDesc_.[[Value]]).
1. Let _secondDesc_ be OrdinaryGetOwnProperty(_partial_, *"second"*).
1. If _secondDesc_ is not *undefined*, then
1. Assert: _secondDesc_ is a data Property Descriptor.
1. Set _result_.[[Second]] to ℝ(_secondDesc_.[[Value]]).
1. Let _millisecondDesc_ be OrdinaryGetOwnProperty(_partial_, *"millisecond"*).
1. If _millisecondDesc_ is not *undefined*, then
1. Assert: _millisecondDesc_ is a data Property Descriptor.
1. Set _result_.[[Millisecond]] to ℝ(_millisecondDesc_.[[Value]]).
1. Let _microsecondDesc_ be OrdinaryGetOwnProperty(_partial_, *"microsecond"*).
1. If _microsecondDesc_ is not *undefined*, then
1. Assert: _microsecondDesc_ is a data Property Descriptor.
1. Set _result_.[[Microsecond]] to ℝ(_microsecondDesc_.[[Value]]).
1. Let _nanosecondDesc_ be OrdinaryGetOwnProperty(_partial_, *"nanosecond"*).
1. If _nanosecondDesc_ is not *undefined*, then
1. Assert: _nanosecondDesc_ is a data Property Descriptor.
1. Set _result_.[[Nanosecond]] to ℝ(_nanosecondDesc_.[[Value]]).
1. Let _result_ be a new TemporalTimeLike Record with each field set to ~unset~.
1. Let _any_ be *false*.
1. Let _hour_ be ? Get(_temporalTimeLike_, *"hour"*).
1. If _hour_ is not *undefined*, then
1. Set _result_.[[Hour]] to ? ToIntegerWithTruncation(_hour_).
1. Set _any_ to *true*.
1. Let _microsecond_ be ? Get(_temporalTimeLike_, *"microsecond"*).
1. If _microsecond_ is not *undefined*, then
1. Set _result_.[[Microsecond]] to ? ToIntegerWithTruncation(_microsecond_).
1. Set _any_ to *true*.
1. Let _millisecond_ be ? Get(_temporalTimeLike_, *"millisecond"*).
1. If _millisecond_ is not *undefined*, then
1. Set _result_.[[Millisecond]] to ? ToIntegerWithTruncation(_millisecond_).
1. Set _any_ to *true*.
1. Let _minute_ be ? Get(_temporalTimeLike_, *"minute"*).
1. If _minute_ is not *undefined*, then
1. Set _result_.[[Minute]] to ? ToIntegerWithTruncation(_minute_).
1. Set _any_ to *true*.
1. Let _nanosecond_ be ? Get(_temporalTimeLike_, *"nanosecond"*).
1. If _nanosecond_ is not *undefined*, then
1. Set _result_.[[Nanosecond]] to ? ToIntegerWithTruncation(_nanosecond_).
1. Set _any_ to *true*.
1. Let _second_ be ? Get(_temporalTimeLike_, *"second"*).
1. If _second_ is not *undefined*, then
1. Set _result_.[[Second]] to ? ToIntegerWithTruncation(_second_).
1. Set _any_ to *true*.
1. If _any_ is *false*, throw a *TypeError* exception.
1. Return _result_.
</emu-alg>

Loading