forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Tests for normative changes around date-only strings
As per the discussion in tc39/proposal-temporal#2379 (comment) and the PR tc39/proposal-temporal#2398, which is to be presented for consensus to TC39 in the upcoming plenary meeting, UTC offsets and the Z designator should be disallowed after any date-only strings (YYYY-MM-DD, YYYY-MM, and MM-DD). They should only be allowed to follow a time component. Z remains disallowed in any string being parsed into a Plain type. Annotations become allowed after any ISO string, even YYYY-MM and MM-DD where they were previously disallowed.
- Loading branch information
Showing
90 changed files
with
3,105 additions
and
210 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-string-date-with-utc-offset.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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dateadd | ||
description: UTC offset not valid with format that does not include a time | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const validStrings = [ | ||
"2000-05-02T00+00:00", | ||
"2000-05-02T00+00:00[UTC]", | ||
"2000-05-02T00+00:00[!UTC]", | ||
"2000-05-02T00-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
const result = instance.dateAdd(arg, new Temporal.Duration()); | ||
|
||
TemporalHelpers.assertPlainDate( | ||
result, | ||
2000, 5, "M05", 2, | ||
`"${arg}" is a valid UTC offset with time for PlainDate` | ||
); | ||
} | ||
|
||
const invalidStrings = [ | ||
"2022-09-15Z", | ||
"2022-09-15Z[UTC]", | ||
"2022-09-15Z[Europe/Vienna]", | ||
"2022-09-15+00:00", | ||
"2022-09-15+00:00[UTC]", | ||
"2022-09-15-02:30", | ||
"2022-09-15-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dateAdd(arg, new Temporal.Duration()), | ||
`"${arg}" UTC offset without time is not valid for PlainDate` | ||
); | ||
} |
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
49 changes: 49 additions & 0 deletions
49
test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-string-date-with-utc-offset.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,49 @@ | ||
// 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.calendar.prototype.dateuntil | ||
description: UTC offset not valid with format that does not include a time | ||
features: [Temporal] | ||
includes: [temporalHelpers.js] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const validStrings = [ | ||
"2000-05-02T00+00:00", | ||
"2000-05-02T00+00:00[UTC]", | ||
"2000-05-02T00+00:00[!UTC]", | ||
"2000-05-02T00-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
TemporalHelpers.assertDuration( | ||
instance.dateUntil(arg, arg), | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
`"${arg}" is a valid UTC offset with time for PlainDate` | ||
); | ||
} | ||
|
||
const invalidStrings = [ | ||
"2022-09-15Z", | ||
"2022-09-15Z[UTC]", | ||
"2022-09-15Z[Europe/Vienna]", | ||
"2022-09-15+00:00", | ||
"2022-09-15+00:00[UTC]", | ||
"2022-09-15-02:30", | ||
"2022-09-15-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), | ||
`"${arg}" UTC offset without time is not valid for PlainDate (first argument)` | ||
); | ||
assert.throws( | ||
RangeError, | ||
() => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), | ||
`"${arg}" UTC offset without time is not valid for PlainDate (second argument)` | ||
); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
test/built-ins/Temporal/Calendar/prototype/day/argument-string-date-with-utc-offset.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,45 @@ | ||
// 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.calendar.prototype.day | ||
description: UTC offset not valid with format that does not include a time | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const validStrings = [ | ||
"2000-05-02T00+00:00", | ||
"2000-05-02T00+00:00[UTC]", | ||
"2000-05-02T00+00:00[!UTC]", | ||
"2000-05-02T00-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
const result = instance.day(arg); | ||
|
||
assert.sameValue( | ||
result, | ||
2, | ||
`"${arg}" is a valid UTC offset with time for PlainDate` | ||
); | ||
} | ||
|
||
const invalidStrings = [ | ||
"2022-09-15Z", | ||
"2022-09-15Z[UTC]", | ||
"2022-09-15Z[Europe/Vienna]", | ||
"2022-09-15+00:00", | ||
"2022-09-15+00:00[UTC]", | ||
"2022-09-15-02:30", | ||
"2022-09-15-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.day(arg), | ||
`"${arg}" UTC offset without time is not valid for PlainDate` | ||
); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-string-date-with-utc-offset.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,45 @@ | ||
// 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.calendar.prototype.dayofweek | ||
description: UTC offset not valid with format that does not include a time | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const validStrings = [ | ||
"2000-05-02T00+00:00", | ||
"2000-05-02T00+00:00[UTC]", | ||
"2000-05-02T00+00:00[!UTC]", | ||
"2000-05-02T00-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
const result = instance.dayOfWeek(arg); | ||
|
||
assert.sameValue( | ||
result, | ||
2, | ||
`"${arg}" is a valid UTC offset with time for PlainDate` | ||
); | ||
} | ||
|
||
const invalidStrings = [ | ||
"2022-09-15Z", | ||
"2022-09-15Z[UTC]", | ||
"2022-09-15Z[Europe/Vienna]", | ||
"2022-09-15+00:00", | ||
"2022-09-15+00:00[UTC]", | ||
"2022-09-15-02:30", | ||
"2022-09-15-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dayOfWeek(arg), | ||
`"${arg}" UTC offset without time is not valid for PlainDate` | ||
); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-string-date-with-utc-offset.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,45 @@ | ||
// 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.calendar.prototype.dayofyear | ||
description: UTC offset not valid with format that does not include a time | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const validStrings = [ | ||
"2000-05-02T00+00:00", | ||
"2000-05-02T00+00:00[UTC]", | ||
"2000-05-02T00+00:00[!UTC]", | ||
"2000-05-02T00-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
const result = instance.dayOfYear(arg); | ||
|
||
assert.sameValue( | ||
result, | ||
123, | ||
`"${arg}" is a valid UTC offset with time for PlainDate` | ||
); | ||
} | ||
|
||
const invalidStrings = [ | ||
"2022-09-15Z", | ||
"2022-09-15Z[UTC]", | ||
"2022-09-15Z[Europe/Vienna]", | ||
"2022-09-15+00:00", | ||
"2022-09-15+00:00[UTC]", | ||
"2022-09-15-02:30", | ||
"2022-09-15-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.dayOfYear(arg), | ||
`"${arg}" UTC offset without time is not valid for PlainDate` | ||
); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
...built-ins/Temporal/Calendar/prototype/daysInMonth/argument-string-date-with-utc-offset.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,45 @@ | ||
// 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.calendar.prototype.daysinmonth | ||
description: UTC offset not valid with format that does not include a time | ||
features: [Temporal] | ||
---*/ | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
|
||
const validStrings = [ | ||
"2000-05-02T00+00:00", | ||
"2000-05-02T00+00:00[UTC]", | ||
"2000-05-02T00+00:00[!UTC]", | ||
"2000-05-02T00-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of validStrings) { | ||
const result = instance.daysInMonth(arg); | ||
|
||
assert.sameValue( | ||
result, | ||
31, | ||
`"${arg}" is a valid UTC offset with time for PlainDate` | ||
); | ||
} | ||
|
||
const invalidStrings = [ | ||
"2022-09-15Z", | ||
"2022-09-15Z[UTC]", | ||
"2022-09-15Z[Europe/Vienna]", | ||
"2022-09-15+00:00", | ||
"2022-09-15+00:00[UTC]", | ||
"2022-09-15-02:30", | ||
"2022-09-15-02:30[America/St_Johns]", | ||
]; | ||
|
||
for (const arg of invalidStrings) { | ||
assert.throws( | ||
RangeError, | ||
() => instance.daysInMonth(arg), | ||
`"${arg}" UTC offset without time is not valid for PlainDate` | ||
); | ||
} |
Oops, something went wrong.