mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 22:15:24 +02:00
Temporal: Coverage for Temporal.ZonedDateTime
This commit is contained in:
parent
4ceee16fff
commit
4aa9379068
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.from
|
||||||
|
description: >
|
||||||
|
Start-of-day is outside the valid epoch nanoseconds limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.from ( item [ , options ] )
|
||||||
|
|
||||||
|
1. Return ? ToTemporalZonedDateTime(item, options).
|
||||||
|
|
||||||
|
ToTemporalZonedDateTime ( item [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let epochNanoseconds be ? InterpretISODateTimeOffset(isoDate, time,
|
||||||
|
offsetBehaviour, offsetNanoseconds, timeZone, disambiguation, offsetOption,
|
||||||
|
matchBehaviour).
|
||||||
|
...
|
||||||
|
|
||||||
|
InterpretISODateTimeOffset ( isoDate, time, offsetBehaviour, offsetNanoseconds,
|
||||||
|
timeZone, disambiguation, offsetOption, matchBehaviour )
|
||||||
|
|
||||||
|
1. If time is start-of-day, then
|
||||||
|
a. Assert: offsetBehaviour is wall.
|
||||||
|
b. Assert: offsetNanoseconds is 0.
|
||||||
|
c. Return ? GetStartOfDay(timeZone, isoDate).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
RangeError,
|
||||||
|
() => Temporal.ZonedDateTime.from("-271821-04-20[+01]"),
|
||||||
|
"From '-271821-04-20[+01]'"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
RangeError,
|
||||||
|
() => Temporal.ZonedDateTime.from("+275760-09-13[-01]"),
|
||||||
|
"From '+275760-09-13[-01]'"
|
||||||
|
);
|
@ -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.zoneddatetime
|
||||||
|
description: >
|
||||||
|
OrdinaryCreateFromConstructor returns with an abrupt completion.
|
||||||
|
info: |
|
||||||
|
CreateTemporalZonedDateTime ( epochNanoseconds, timeZone, calendar [ , newTarget ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Let object be ? OrdinaryCreateFromConstructor(newTarget,
|
||||||
|
"%Temporal.ZonedDateTime.prototype%", « [[InitializedTemporalZonedDateTime]],
|
||||||
|
[[EpochNanoseconds]], [[TimeZone]], [[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.ZonedDateTime, [0n, "UTC"], newTarget)
|
||||||
|
});
|
42
test/built-ins/Temporal/ZonedDateTime/limits.js
Normal file
42
test/built-ins/Temporal/ZonedDateTime/limits.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime
|
||||||
|
description: >
|
||||||
|
RangeError thrown when epoch nanoseconds not valid.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime ( epochNanoseconds, timeZone [ , calendar ] )
|
||||||
|
|
||||||
|
2. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
|
||||||
|
3. If IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nsMaxInstant = 864n * 10n ** 19n;
|
||||||
|
var nsMinInstant = -nsMaxInstant;
|
||||||
|
|
||||||
|
var invalidEpochNanoseconds = [
|
||||||
|
nsMaxInstant + 1n,
|
||||||
|
nsMinInstant - 1n,
|
||||||
|
2n ** 128n,
|
||||||
|
-(2n ** 128n),
|
||||||
|
];
|
||||||
|
|
||||||
|
var timeZones = [
|
||||||
|
"UTC",
|
||||||
|
"+00",
|
||||||
|
"+01",
|
||||||
|
"-01",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var timeZone of timeZones) {
|
||||||
|
for (var epochNs of invalidEpochNanoseconds) {
|
||||||
|
assert.throws(
|
||||||
|
RangeError,
|
||||||
|
() => new Temporal.ZonedDateTime(epochNs, timeZone),
|
||||||
|
`epochNs = ${epochNs}, timeZone = ${timeZone}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.add
|
||||||
|
description: >
|
||||||
|
Throws RangeError when intermediate date-time is outside valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.add ( temporalDurationLike [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Return ? AddDurationToZonedDateTime(add, zonedDateTime, temporalDurationLike, options).
|
||||||
|
|
||||||
|
AddDurationToZonedDateTime ( operation, zonedDateTime, temporalDurationLike, options )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let epochNanoseconds be ? AddZonedDateTime(zonedDateTime.[[EpochNanoseconds]], timeZone, calendar, internalDuration, overflow).
|
||||||
|
...
|
||||||
|
|
||||||
|
AddZonedDateTime ( epochNanoseconds, timeZone, calendar, duration, overflow )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Let intermediateDateTime be CombineISODateAndTimeRecord(addedDate, isoDateTime.[[Time]]).
|
||||||
|
5. If ISODateTimeWithinLimits(intermediateDateTime) is false, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nsMaxInstant = 864n * 10n**19n;
|
||||||
|
var nsMinInstant = -nsMaxInstant;
|
||||||
|
|
||||||
|
var epochNs = nsMinInstant;
|
||||||
|
var zdt = new Temporal.ZonedDateTime(epochNs, "UTC");
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => zdt.add({days: -1}));
|
31
test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/basic.js
vendored
Normal file
31
test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/basic.js
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.hoursinday
|
||||||
|
description: >
|
||||||
|
Basic tests for hoursInDay.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nsPerDay = 24n * 60n * 60n * 1000n * 1000n * 1000n;
|
||||||
|
|
||||||
|
var epochNanoseconds = [
|
||||||
|
0n,
|
||||||
|
nsPerDay,
|
||||||
|
-nsPerDay,
|
||||||
|
];
|
||||||
|
|
||||||
|
var timeZones = [
|
||||||
|
"UTC",
|
||||||
|
"+00",
|
||||||
|
"+01",
|
||||||
|
"-01",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var timeZone of timeZones) {
|
||||||
|
for (var epochNs of epochNanoseconds) {
|
||||||
|
var zdt = new Temporal.ZonedDateTime(epochNs, timeZone);
|
||||||
|
assert.sameValue(zdt.hoursInDay, 24, `epochNs = ${epochNs}, timeZone = ${timeZone}`);
|
||||||
|
}
|
||||||
|
}
|
30
test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/get-start-of-day-throws.js
vendored
Normal file
30
test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/get-start-of-day-throws.js
vendored
Normal file
@ -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.zoneddatetime.prototype.hoursinday
|
||||||
|
description: >
|
||||||
|
GetStartOfDay throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
get Temporal.ZonedDateTime.prototype.hoursInDay
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Let todayNs be ? GetStartOfDay(timeZone, today).
|
||||||
|
8. Let tomorrowNs be ? GetStartOfDay(timeZone, tomorrow).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var zdt;
|
||||||
|
|
||||||
|
// GetStartOfDay for |today| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.hoursInDay);
|
||||||
|
|
||||||
|
// GetStartOfDay for |today| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "+01");
|
||||||
|
assert.throws(RangeError, () => zdt.hoursInDay);
|
||||||
|
|
||||||
|
// GetStartOfDay for |tomorrow| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.hoursInDay);
|
43
test/built-ins/Temporal/ZonedDateTime/prototype/round/get-start-of-day-throws.js
vendored
Normal file
43
test/built-ins/Temporal/ZonedDateTime/prototype/round/get-start-of-day-throws.js
vendored
Normal file
@ -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.zoneddatetime.prototype.round
|
||||||
|
description: >
|
||||||
|
GetStartOfDay throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.round ( roundTo )
|
||||||
|
|
||||||
|
...
|
||||||
|
18. If smallestUnit is day, then
|
||||||
|
...
|
||||||
|
c. Let startNs be ? GetStartOfDay(timeZone, dateStart).
|
||||||
|
...
|
||||||
|
e. Let endNs be ? GetStartOfDay(timeZone, dateEnd).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var roundTo = {smallestUnit: "days"};
|
||||||
|
|
||||||
|
var zdt;
|
||||||
|
|
||||||
|
// GetStartOfDay for |dateStart| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.round(roundTo));
|
||||||
|
|
||||||
|
// GetStartOfDay for |dateStart| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "+01");
|
||||||
|
assert.throws(RangeError, () => zdt.round(roundTo));
|
||||||
|
|
||||||
|
// GetStartOfDay for |dateEnd| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.round(roundTo));
|
||||||
|
|
||||||
|
// GetStartOfDay for |dateEnd| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(864n * 10n**19n, "+00");
|
||||||
|
assert.throws(RangeError, () => zdt.round(roundTo));
|
||||||
|
|
||||||
|
// GetStartOfDay for |dateEnd| fails.
|
||||||
|
zdt = new Temporal.ZonedDateTime(864n * 10n**19n, "+01");
|
||||||
|
assert.throws(RangeError, () => zdt.round(roundTo));
|
38
test/built-ins/Temporal/ZonedDateTime/prototype/round/rounded-date-time-outside-valid-limits.js
vendored
Normal file
38
test/built-ins/Temporal/ZonedDateTime/prototype/round/rounded-date-time-outside-valid-limits.js
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.round
|
||||||
|
description: >
|
||||||
|
Throws RangeError when rounded ISO date-time is outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.round ( roundTo )
|
||||||
|
|
||||||
|
...
|
||||||
|
18. If smallestUnit is day, then
|
||||||
|
...
|
||||||
|
19. Else,
|
||||||
|
a. Let roundResult be RoundISODateTime(isoDateTime, roundingIncrement,
|
||||||
|
smallestUnit, roundingMode).
|
||||||
|
...
|
||||||
|
c. Let epochNanoseconds be ? InterpretISODateTimeOffset(roundResult.[[ISODate]],
|
||||||
|
roundResult.[[Time]], option, offsetNanoseconds, timeZone, compatible, prefer,
|
||||||
|
match-exactly).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nsMaxInstant = 864n * 10n**19n;
|
||||||
|
|
||||||
|
var epochNs = nsMaxInstant;
|
||||||
|
var zdt = new Temporal.ZonedDateTime(epochNs, "+23:59");
|
||||||
|
|
||||||
|
var roundTo = {
|
||||||
|
smallestUnit: "minutes",
|
||||||
|
roundingIncrement: 10,
|
||||||
|
roundingMode: "ceil",
|
||||||
|
};
|
||||||
|
|
||||||
|
// |isoDateTime| is +275760-09-13T23:59.
|
||||||
|
// |roundResult| is +275760-09-14T00:00, which is outside the valid limits.
|
||||||
|
assert.throws(RangeError, () => zdt.round(roundTo));
|
69
test/built-ins/Temporal/ZonedDateTime/prototype/since/same-epoch-nanoseconds.js
vendored
Normal file
69
test/built-ins/Temporal/ZonedDateTime/prototype/since/same-epoch-nanoseconds.js
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.since
|
||||||
|
description: >
|
||||||
|
Returns a blank duration when epoch nanoseconds are equal.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.since ( other [ , options ] )
|
||||||
|
|
||||||
|
3. Return ? DifferenceTemporalZonedDateTime(since, zonedDateTime, other, options).
|
||||||
|
|
||||||
|
DifferenceTemporalZonedDateTime ( operation, zonedDateTime, other, options )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. If zonedDateTime.[[EpochNanoseconds]] = other.[[EpochNanoseconds]], then
|
||||||
|
a. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0).
|
||||||
|
...
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var epochNanoseconds = [
|
||||||
|
0n,
|
||||||
|
1n,
|
||||||
|
-1n,
|
||||||
|
];
|
||||||
|
|
||||||
|
var timeZones = [
|
||||||
|
"UTC",
|
||||||
|
"+00",
|
||||||
|
"+01",
|
||||||
|
"-01",
|
||||||
|
];
|
||||||
|
|
||||||
|
var units = [
|
||||||
|
"years",
|
||||||
|
"months",
|
||||||
|
"weeks",
|
||||||
|
"days",
|
||||||
|
"hours",
|
||||||
|
"minutes",
|
||||||
|
"seconds",
|
||||||
|
"milliseconds",
|
||||||
|
"microseconds",
|
||||||
|
"nanoseconds",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var timeZone of timeZones) {
|
||||||
|
for (var epochNs of epochNanoseconds) {
|
||||||
|
var zdt = new Temporal.ZonedDateTime(epochNs, timeZone);
|
||||||
|
var other = new Temporal.ZonedDateTime(epochNs, timeZone);
|
||||||
|
|
||||||
|
for (var i = 0; i < units.length; ++i) {
|
||||||
|
for (var j = i; j < units.length; ++j) {
|
||||||
|
var options = {
|
||||||
|
largestUnit: units[i],
|
||||||
|
smallestUnit: units[j],
|
||||||
|
};
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
zdt.since(other, options),
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
`epochNs = ${epochNs}, timeZone = ${timeZone}, options = ${JSON.stringify(options)})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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.zoneddatetime.prototype.startofday
|
||||||
|
description: >
|
||||||
|
GetStartOfDay throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.startOfDay ( )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Let epochNanoseconds be ? GetStartOfDay(timeZone, isoDateTime.[[ISODate]]).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var zdt;
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.startOfDay());
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "+01");
|
||||||
|
assert.throws(RangeError, () => zdt.startOfDay());
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "+00");
|
||||||
|
assert(zdt.startOfDay().equals(zdt));
|
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.subtract
|
||||||
|
description: >
|
||||||
|
Throws RangeError when intermediate date-time is outside valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.subtract ( temporalDurationLike [ , options ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
3. Return ? AddDurationToZonedDateTime(subtract, zonedDateTime, temporalDurationLike, options).
|
||||||
|
|
||||||
|
AddDurationToZonedDateTime ( operation, zonedDateTime, temporalDurationLike, options )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. Let epochNanoseconds be ? AddZonedDateTime(zonedDateTime.[[EpochNanoseconds]], timeZone, calendar, internalDuration, overflow).
|
||||||
|
...
|
||||||
|
|
||||||
|
AddZonedDateTime ( epochNanoseconds, timeZone, calendar, duration, overflow )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. Let intermediateDateTime be CombineISODateAndTimeRecord(addedDate, isoDateTime.[[Time]]).
|
||||||
|
5. If ISODateTimeWithinLimits(intermediateDateTime) is false, throw a RangeError exception.
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nsMaxInstant = 864n * 10n**19n;
|
||||||
|
var nsMinInstant = -nsMaxInstant;
|
||||||
|
|
||||||
|
var epochNs = nsMinInstant;
|
||||||
|
var zdt = new Temporal.ZonedDateTime(epochNs, "UTC");
|
||||||
|
|
||||||
|
assert.throws(RangeError, () => zdt.subtract({days: 1}));
|
69
test/built-ins/Temporal/ZonedDateTime/prototype/until/same-epoch-nanoseconds.js
vendored
Normal file
69
test/built-ins/Temporal/ZonedDateTime/prototype/until/same-epoch-nanoseconds.js
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.until
|
||||||
|
description: >
|
||||||
|
Returns a blank duration when epoch nanoseconds are equal.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.until ( other [ , options ] )
|
||||||
|
|
||||||
|
3. Return ? DifferenceTemporalZonedDateTime(until, zonedDateTime, other, options).
|
||||||
|
|
||||||
|
DifferenceTemporalZonedDateTime ( operation, zonedDateTime, other, options )
|
||||||
|
|
||||||
|
...
|
||||||
|
8. If zonedDateTime.[[EpochNanoseconds]] = other.[[EpochNanoseconds]], then
|
||||||
|
a. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0).
|
||||||
|
...
|
||||||
|
includes: [temporalHelpers.js]
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var epochNanoseconds = [
|
||||||
|
0n,
|
||||||
|
1n,
|
||||||
|
-1n,
|
||||||
|
];
|
||||||
|
|
||||||
|
var timeZones = [
|
||||||
|
"UTC",
|
||||||
|
"+00",
|
||||||
|
"+01",
|
||||||
|
"-01",
|
||||||
|
];
|
||||||
|
|
||||||
|
var units = [
|
||||||
|
"years",
|
||||||
|
"months",
|
||||||
|
"weeks",
|
||||||
|
"days",
|
||||||
|
"hours",
|
||||||
|
"minutes",
|
||||||
|
"seconds",
|
||||||
|
"milliseconds",
|
||||||
|
"microseconds",
|
||||||
|
"nanoseconds",
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var timeZone of timeZones) {
|
||||||
|
for (var epochNs of epochNanoseconds) {
|
||||||
|
var zdt = new Temporal.ZonedDateTime(epochNs, timeZone);
|
||||||
|
var other = new Temporal.ZonedDateTime(epochNs, timeZone);
|
||||||
|
|
||||||
|
for (var i = 0; i < units.length; ++i) {
|
||||||
|
for (var j = i; j < units.length; ++j) {
|
||||||
|
var options = {
|
||||||
|
largestUnit: units[i],
|
||||||
|
smallestUnit: units[j],
|
||||||
|
};
|
||||||
|
|
||||||
|
TemporalHelpers.assertDuration(
|
||||||
|
zdt.until(other, options),
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
`epochNs = ${epochNs}, timeZone = ${timeZone}, options = ${JSON.stringify(options)})`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/get-start-of-day-throws.js
vendored
Normal file
24
test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/get-start-of-day-throws.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.withplaintime
|
||||||
|
description: >
|
||||||
|
GetStartOfDay throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.withPlainTime ( [ plainTimeLike ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. If plainTimeLike is undefined, then
|
||||||
|
a. Let epochNs be ? GetStartOfDay(timeZone, isoDateTime.[[ISODate]]).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var zdt;
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.withPlainTime());
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "+01");
|
||||||
|
assert.throws(RangeError, () => zdt.withPlainTime());
|
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-temporal.zoneddatetime.prototype.withplaintime
|
||||||
|
description: >
|
||||||
|
Throws a RangeError for values outside the valid limits.
|
||||||
|
info: |
|
||||||
|
Temporal.ZonedDateTime.prototype.withPlainTime ( [ plainTimeLike ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
7. Else,
|
||||||
|
...
|
||||||
|
c. Let epochNs be ? GetEpochNanosecondsFor(timeZone, resultISODateTime, compatible).
|
||||||
|
...
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var zdt;
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "-01");
|
||||||
|
assert.throws(RangeError, () => zdt.withPlainTime("00:00"));
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-864n * 10n**19n, "+01");
|
||||||
|
assert.throws(RangeError, () => zdt.withPlainTime("00:00"));
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(864n * 10n**19n, "UTC");
|
||||||
|
assert.throws(RangeError, () => zdt.withPlainTime("01:00"));
|
28
test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/basic.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/basic.js
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-get-temporal.zoneddatetime.prototype.yearofweek
|
||||||
|
description: >
|
||||||
|
Basic tests for yearOfWeek.
|
||||||
|
features: [Temporal]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var nsPerDay = 864n * 10n ** 11n;
|
||||||
|
|
||||||
|
var zdt;
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(0n, "UTC");
|
||||||
|
assert.sameValue(zdt.yearOfWeek, 1970);
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-3n * nsPerDay, "UTC")
|
||||||
|
assert.sameValue(zdt.yearOfWeek, 1970);
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(-4n * nsPerDay, "UTC")
|
||||||
|
assert.sameValue(zdt.yearOfWeek, 1969);
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(367n * nsPerDay, "UTC")
|
||||||
|
assert.sameValue(zdt.yearOfWeek, 1970);
|
||||||
|
|
||||||
|
zdt = new Temporal.ZonedDateTime(368n * nsPerDay, "UTC")
|
||||||
|
assert.sameValue(zdt.yearOfWeek, 1971);
|
Loading…
x
Reference in New Issue
Block a user