-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Move ZonedDateTime/prototype/round tests and one other Zone…
…dDateTime test out of staging
- Loading branch information
1 parent
70ef1ac
commit de68177
Showing
9 changed files
with
314 additions
and
250 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
test/built-ins/Temporal/ZonedDateTime/prototype/round/rounding-increments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2021 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.zoneddatetime.prototype.round | ||
description: round() rounds to various increments. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00"); | ||
// "1976-11-18T16:00:00+01:00[+01:00]" | ||
const expectedHours = new Temporal.ZonedDateTime(217177200000000000n, "+01:00"); | ||
// "1976-11-18T15:30:00+01:00[+01:00]" | ||
const expectedMinutes = new Temporal.ZonedDateTime(217175400000000000n, "+01:00"); | ||
// "1976-11-18T15:23:30+01:00[+01:00]" | ||
const expectedSeconds = new Temporal.ZonedDateTime(217175010000000000n, "+01:00"); | ||
// "1976-11-18T15:23:30.12+01:00[+01:00]"); | ||
const expectedMilliseconds = new Temporal.ZonedDateTime(217175010120000000n, "+01:00"); | ||
// "1976-11-18T15:23:30.12346+01:00[+01:00]"); | ||
const expectedMicroseconds = new Temporal.ZonedDateTime(217175010123460000n, "+01:00"); | ||
// "1976-11-18T15:23:30.12345679+01:00[+01:00]"); | ||
const expectedNanoseconds = new Temporal.ZonedDateTime(217175010123456790n, "+01:00"); | ||
// "1976-11-19T00:00:00+01:00[+01:00]"); | ||
const expected1Day = new Temporal.ZonedDateTime(217206000000000000n, "+01:00"); | ||
|
||
// rounds to an increment of hours | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "hour", | ||
roundingIncrement: 4 | ||
}), expectedHours); | ||
|
||
// rounds to an increment of minutes | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "minute", | ||
roundingIncrement: 15 | ||
}), expectedMinutes); | ||
|
||
// rounds to an increment of seconds | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "second", | ||
roundingIncrement: 30 | ||
}), expectedSeconds); | ||
|
||
// rounds to an increment of milliseconds | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "millisecond", | ||
roundingIncrement: 10 | ||
}), expectedMilliseconds); | ||
|
||
// rounds to an increment of microseconds | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "microsecond", | ||
roundingIncrement: 10 | ||
}), expectedMicroseconds); | ||
|
||
// rounds to an increment of nanoseconds | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "nanosecond", | ||
roundingIncrement: 10 | ||
}), expectedNanoseconds); | ||
|
||
// 1 day is a valid increment | ||
TemporalHelpers.assertZonedDateTimesEqual(zdt.round({ | ||
smallestUnit: "day", | ||
roundingIncrement: 1 | ||
}), expected1Day); | ||
|
26 changes: 26 additions & 0 deletions
26
test/built-ins/Temporal/ZonedDateTime/prototype/round/smallestunit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.zoneddatetime.prototype.round | ||
description: Test various smallestUnit values. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
// const bal = Temporal.ZonedDateTime.from("1976-11-18T23:59:59.999999999+01:00[+01:00]"); | ||
const bal = new Temporal.ZonedDateTime(217205999999999999n, "+01:00"); | ||
// "1976-11-19T00:00:00+01:00[+01:00]" | ||
const expected = new Temporal.ZonedDateTime(217206000000000000n, "+01:00"); | ||
|
||
[ | ||
"day", | ||
"hour", | ||
"minute", | ||
"second", | ||
"millisecond", | ||
"microsecond" | ||
].forEach(smallestUnit => { | ||
TemporalHelpers.assertZonedDateTimesEqual(bal.round( { smallestUnit }), | ||
expected); | ||
}); |
66 changes: 66 additions & 0 deletions
66
test/built-ins/Temporal/ZonedDateTime/prototype/round/throws-on-invalid-increments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.zoneddatetime.prototype.round | ||
description: Throws on invalid increments. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00"); | ||
|
||
// throws on increments that do not divide evenly into the next highest | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "day", | ||
roundingIncrement: 29 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "hour", | ||
roundingIncrement: 29 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "minute", | ||
roundingIncrement: 29 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "second", | ||
roundingIncrement: 29 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "millisecond", | ||
roundingIncrement: 29 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "microsecond", | ||
roundingIncrement: 29 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "nanosecond", | ||
roundingIncrement: 29 | ||
})); | ||
|
||
// throws on increments that are equal to the next highest | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "hour", | ||
roundingIncrement: 24 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "minute", | ||
roundingIncrement: 60 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "second", | ||
roundingIncrement: 60 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "millisecond", | ||
roundingIncrement: 1000 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "microsecond", | ||
roundingIncrement: 1000 | ||
})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
smallestUnit: "nanosecond", | ||
roundingIncrement: 1000 | ||
})); |
12 changes: 12 additions & 0 deletions
12
test/built-ins/Temporal/ZonedDateTime/prototype/round/throws-without-parameter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.zoneddatetime.prototype.round | ||
description: Throws without parameter. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00"); | ||
|
||
assert.throws(TypeError, () => zdt.round()); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/Temporal/ZonedDateTime/prototype/round/throws-without-smallestunit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.zoneddatetime.prototype.round | ||
description: Throws without required smallestUnit parameter. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00"); | ||
|
||
assert.throws(RangeError, () => zdt.round({})); | ||
assert.throws(RangeError, () => zdt.round({ | ||
roundingIncrement: 1, | ||
roundingMode: "ceil" | ||
})); |
80 changes: 80 additions & 0 deletions
80
test/built-ins/Temporal/ZonedDateTime/prototype/round/valid-increments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (C) 2021 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.zoneddatetime.prototype.round | ||
description: Validity of increments depends on divisibility. | ||
features: [Temporal] | ||
---*/ | ||
|
||
const zdt = new Temporal.ZonedDateTime(217175010123456789n, "+01:00"); | ||
|
||
// valid hour increments divide into 24 | ||
const smallestUnit = "hour"; | ||
[ | ||
1, | ||
2, | ||
3, | ||
4, | ||
6, | ||
8, | ||
12 | ||
].forEach(roundingIncrement => { | ||
assert(zdt.round({ | ||
smallestUnit, | ||
roundingIncrement | ||
}) instanceof Temporal.ZonedDateTime); | ||
}); | ||
[ | ||
"minute", | ||
"second" | ||
].forEach(smallestUnit => { | ||
// valid minutes/seconds increments divide into 60`, () => { | ||
[ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
10, | ||
12, | ||
15, | ||
20, | ||
30 | ||
].forEach(roundingIncrement => { | ||
assert(zdt.round({ | ||
smallestUnit, | ||
roundingIncrement | ||
}) instanceof Temporal.ZonedDateTime); | ||
}); | ||
}); | ||
[ | ||
"millisecond", | ||
"microsecond", | ||
"nanosecond" | ||
].forEach(smallestUnit => { | ||
// valid increments divide into 1000` | ||
[ | ||
1, | ||
2, | ||
4, | ||
5, | ||
8, | ||
10, | ||
20, | ||
25, | ||
40, | ||
50, | ||
100, | ||
125, | ||
200, | ||
250, | ||
500 | ||
].forEach(roundingIncrement => { | ||
assert(zdt.round({ | ||
smallestUnit, | ||
roundingIncrement | ||
}) instanceof Temporal.ZonedDateTime); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
test/built-ins/Temporal/ZonedDateTime/prototype/since/reversibility-of-differences.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2018 Bloomberg LP. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.prototype.since | ||
description: Reversibility of differences. | ||
includes: [temporalHelpers.js] | ||
features: [Temporal] | ||
---*/ | ||
|
||
/* | ||
const earlier = Temporal.ZonedDateTime.from("1976-11-18T15:23:30.123456789-03:00[-03:00]"); | ||
const later = Temporal.ZonedDateTime.from("2019-10-29T10:46:38.271986102-03:00[-03:00]"); | ||
*/ | ||
const earlier = new Temporal.ZonedDateTime(217189410123456789n, "-03:00"); | ||
const later = new Temporal.ZonedDateTime(1572356798271986102n, "-03:00"); | ||
|
||
[ | ||
"hours", | ||
"minutes", | ||
"seconds" | ||
].forEach(largestUnit => { | ||
const diff = later.since(earlier, { largestUnit }); | ||
TemporalHelpers.assertDurationsEqual(earlier.since(later, { largestUnit }), | ||
diff.negated()) | ||
TemporalHelpers.assertDurationsEqual(earlier.until(later, { largestUnit }), | ||
diff); | ||
// difference symmetrical with regard to negative durations | ||
assert(earlier.subtract(diff.negated()).equals(later)); | ||
assert(later.add(diff.negated()).equals(earlier)); | ||
}); | ||
|
||
[ | ||
"years", | ||
"months", | ||
"weeks", | ||
"days", | ||
"hours", | ||
"minutes", | ||
"seconds" | ||
].forEach(largestUnit => { | ||
const diff1 = earlier.until(later, { largestUnit }); | ||
const diff2 = later.since(earlier, { largestUnit }); | ||
assert(earlier.add(diff1).equals(later)); | ||
assert(later.subtract(diff2).equals(earlier)); | ||
}); |
37 changes: 0 additions & 37 deletions
37
test/staging/Temporal/ZonedDateTime/old/reversibility-of-differences.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.