mirror of
https://github.com/tc39/test262.git
synced 2025-07-29 17:04:31 +02:00
Temporal: Coverage for Temporal.PlainDate
This commit is contained in:
parent
934563c6c4
commit
22539853cd
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate
|
||||||
|
description: >
|
||||||
|
OrdinaryCreateFromConstructor returns with an abrupt completion.
|
||||||
|
info: |
|
||||||
|
CreateTemporalDate ( isoDate, calendar [ , newTarget ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Let object be ? OrdinaryCreateFromConstructor(newTarget,
|
||||||
|
"%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISODate]],
|
||||||
|
[[Calendar]] »).
|
||||||
|
...
|
||||||
|
|
||||||
|
OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
|
||||||
|
...
|
||||||
|
|
||||||
|
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
|
||||||
|
|
||||||
|
...
|
||||||
|
2. Let proto be ? Get(constructor, "prototype").
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
|
||||||
|
get() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function() {
|
||||||
|
Reflect.construct(Temporal.PlainDate, [1970, 1, 1], newTarget)
|
||||||
|
});
|
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.since
|
||||||
|
description: >
|
||||||
|
Throws if rounded date outside valid ISO date range.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.since ( other [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Return ? DifferenceTemporalPlainDate(since, temporalDate, other, options).
|
||||||
|
|
||||||
|
DifferenceTemporalPlainDate ( operation, temporalDate, other, options )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. If settings.[[SmallestUnit]] is not day or settings.[[RoundingIncrement]] ≠ 1, then
|
||||||
|
...
|
||||||
|
d. Set duration to ? RoundRelativeDuration(duration, destEpochNs, isoDateTime,
|
||||||
|
unset, temporalDate.[[Calendar]], settings.[[LargestUnit]],
|
||||||
|
settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]]).
|
||||||
|
...
|
||||||
|
|
||||||
|
RoundRelativeDuration ( duration, destEpochNs, isoDateTime, timeZone, calendar,
|
||||||
|
largestUnit, increment, smallestUnit, roundingMode )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If irregularLengthUnit is true, then
|
||||||
|
a. Let record be ? NudgeToCalendarUnit(sign, duration, destEpochNs, isoDateTime,
|
||||||
|
timeZone, calendar, increment, smallestUnit, roundingMode).
|
||||||
|
...
|
||||||
|
|
||||||
|
NudgeToCalendarUnit ( sign, duration, destEpochNs, isoDateTime, timeZone, calendar,
|
||||||
|
increment, unit, roundingMode )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let end be ? CalendarDateAdd(calendar, isoDateTime.[[ISODate]], endDuration, constrain).
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var from = new Temporal.PlainDate(1970, 1, 1);
|
||||||
|
var to = new Temporal.PlainDate(1971, 1, 1);
|
||||||
|
var options = {roundingIncrement: 100_000_000, smallestUnit: "months"};
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => from.since(to, options));
|
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||||
|
description: >
|
||||||
|
Accessor property for "plainTime" throws an error.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.toZonedDateTime ( item )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If item is an Object, then
|
||||||
|
a. Let timeZoneLike be ? Get(item, "timeZone").
|
||||||
|
b. If timeZoneLike is undefined, then
|
||||||
|
...
|
||||||
|
c. Else,
|
||||||
|
i. Let timeZone be ? ToTemporalTimeZoneIdentifier(timeZoneLike).
|
||||||
|
ii. Let temporalTime be ? Get(item, "plainTime").
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var instance = new Temporal.PlainDate(1970, 1, 1);
|
||||||
|
|
||||||
|
var item = {
|
||||||
|
timeZone: "UTC",
|
||||||
|
get plainTime() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, () => instance.toZonedDateTime(item));
|
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||||
|
description: >
|
||||||
|
Accessor property for "timeZone" throws an error.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.toZonedDateTime ( item )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If item is an Object, then
|
||||||
|
a. Let timeZoneLike be ? Get(item, "timeZone").
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var instance = new Temporal.PlainDate(1970, 1, 1);
|
||||||
|
|
||||||
|
var item = {
|
||||||
|
get timeZone() {
|
||||||
|
throw new Test262Error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(Test262Error, () => instance.toZonedDateTime(item));
|
@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||||
|
description: >
|
||||||
|
Property "timeZone" can't be parsed as a time zone.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.toZonedDateTime ( item )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. If item is an Object, then
|
||||||
|
a. Let timeZoneLike be ? Get(item, "timeZone").
|
||||||
|
b. If timeZoneLike is undefined, then
|
||||||
|
..
|
||||||
|
c. Else,
|
||||||
|
i. Let timeZone be ? ToTemporalTimeZoneIdentifier(timeZoneLike).
|
||||||
|
...
|
||||||
|
|
||||||
|
ToTemporalTimeZoneIdentifier ( temporalTimeZoneLike )
|
||||||
|
|
||||||
|
1. If temporalTimeZoneLike is an Object, then
|
||||||
|
...
|
||||||
|
2. If temporalTimeZoneLike is not a String, throw a TypeError exception.
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var instance = new Temporal.PlainDate(1970, 1, 1);
|
||||||
|
|
||||||
|
for (var timeZone of [
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
0n,
|
||||||
|
Symbol(),
|
||||||
|
{},
|
||||||
|
[],
|
||||||
|
function() {},
|
||||||
|
]) {
|
||||||
|
var item = {timeZone};
|
||||||
|
assert.throws(TypeError, () => instance.toZonedDateTime(item));
|
||||||
|
}
|
46
test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-epoch-nanoseconds-for-throws.js
vendored
Normal file
46
test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-epoch-nanoseconds-for-throws.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||||
|
description: >
|
||||||
|
GetEpochNanosecondsFor throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.toZonedDateTime ( item )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If temporalTime is undefined, then
|
||||||
|
...
|
||||||
|
6. Else,
|
||||||
|
...
|
||||||
|
d. Let epochNs be ? GetEpochNanosecondsFor(timeZone, isoDateTime, compatible).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var minDate = new Temporal.PlainDate(-271821, 4, 19);
|
||||||
|
var minDateTime = new Temporal.PlainDate(-271821, 4, 20);
|
||||||
|
var maxDate = new Temporal.PlainDate(275760, 9, 13);
|
||||||
|
|
||||||
|
var midnight = new Temporal.PlainTime();
|
||||||
|
var oneHourPastMidnight = new Temporal.PlainTime(1);
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => minDate.toZonedDateTime({
|
||||||
|
timeZone: "UTC",
|
||||||
|
plainTime: oneHourPastMidnight,
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => minDate.toZonedDateTime({
|
||||||
|
timeZone: "+00",
|
||||||
|
plainTime: oneHourPastMidnight,
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => minDateTime.toZonedDateTime({
|
||||||
|
timeZone: "+01",
|
||||||
|
temporalTime: midnight,
|
||||||
|
}));
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => maxDate.toZonedDateTime({
|
||||||
|
timeZone: "-01",
|
||||||
|
temporalTime: midnight,
|
||||||
|
}));
|
25
test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-start-of-day-throws.js
vendored
Normal file
25
test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-start-of-day-throws.js
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||||
|
description: >
|
||||||
|
GetStartOfDay throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.toZonedDateTime ( item )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If temporalTime is undefined, then
|
||||||
|
a. Let epochNs be ? GetStartOfDay(timeZone, temporalDate.[[ISODate]]).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var minDate = new Temporal.PlainDate(-271821, 4, 19);
|
||||||
|
var minDateTime = new Temporal.PlainDate(-271821, 4, 20);
|
||||||
|
var maxDate = new Temporal.PlainDate(275760, 9, 13);
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => minDate.toZonedDateTime("UTC"));
|
||||||
|
assert.throws(RangeError, () => minDate.toZonedDateTime("+00"));
|
||||||
|
assert.throws(RangeError, () => minDateTime.toZonedDateTime("+01"));
|
||||||
|
assert.throws(RangeError, () => maxDate.toZonedDateTime("-01"));
|
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.tozoneddatetime
|
||||||
|
description: >
|
||||||
|
Throws if combined date-time outside valid ISO date range.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.toZonedDateTime ( item )
|
||||||
|
|
||||||
|
1. Let temporalDate be the this value.
|
||||||
|
...
|
||||||
|
5. If temporalTime is undefined, then
|
||||||
|
...
|
||||||
|
6. Else,
|
||||||
|
a. Set temporalTime to ? ToTemporalTime(temporalTime).
|
||||||
|
b. Let isoDateTime be CombineISODateAndTimeRecord(temporalDate.[[ISODate]], temporalTime.[[Time]]).
|
||||||
|
c. If ISODateTimeWithinLimits(isoDateTime) is false, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var minDate = new Temporal.PlainDate(-271821, 4, 19);
|
||||||
|
var midnight = new Temporal.PlainTime();
|
||||||
|
var item = {
|
||||||
|
timeZone: "+00",
|
||||||
|
plainTime: midnight,
|
||||||
|
};
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => minDate.toZonedDateTime(item));
|
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.plaindate.prototype.until
|
||||||
|
description: >
|
||||||
|
Throws if rounded date outside valid ISO date range.
|
||||||
|
info: |
|
||||||
|
Temporal.PlainDate.prototype.until ( other [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Return ? DifferenceTemporalPlainDate(until, temporalDate, other, options).
|
||||||
|
|
||||||
|
DifferenceTemporalPlainDate ( operation, temporalDate, other, options )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. If settings.[[SmallestUnit]] is not day or settings.[[RoundingIncrement]] ≠ 1, then
|
||||||
|
...
|
||||||
|
d. Set duration to ? RoundRelativeDuration(duration, destEpochNs, isoDateTime,
|
||||||
|
unset, temporalDate.[[Calendar]], settings.[[LargestUnit]],
|
||||||
|
settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]]).
|
||||||
|
...
|
||||||
|
|
||||||
|
RoundRelativeDuration ( duration, destEpochNs, isoDateTime, timeZone, calendar,
|
||||||
|
largestUnit, increment, smallestUnit, roundingMode )
|
||||||
|
|
||||||
|
...
|
||||||
|
5. If irregularLengthUnit is true, then
|
||||||
|
a. Let record be ? NudgeToCalendarUnit(sign, duration, destEpochNs, isoDateTime,
|
||||||
|
timeZone, calendar, increment, smallestUnit, roundingMode).
|
||||||
|
...
|
||||||
|
|
||||||
|
NudgeToCalendarUnit ( sign, duration, destEpochNs, isoDateTime, timeZone, calendar,
|
||||||
|
increment, unit, roundingMode )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let end be ? CalendarDateAdd(calendar, isoDateTime.[[ISODate]], endDuration, constrain).
|
||||||
|
...
|
||||||
|
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var from = new Temporal.PlainDate(1970, 1, 1);
|
||||||
|
var to = new Temporal.PlainDate(1971, 1, 1);
|
||||||
|
var options = {roundingIncrement: 100_000_000, smallestUnit: "months"};
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => from.until(to, options));
|
Loading…
x
Reference in New Issue
Block a user