From 13a6fe7ac30bbb2b48a503c130ece2b509762ece Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 19 Jul 2021 11:50:58 -0700 Subject: [PATCH 1/3] Add tests for Temporal.Calendar.p*.inLeapYear --- .../prototype/inLeapYear/plain-date-time.js | 30 +++++++++++++ .../prototype/inLeapYear/plain-date.js | 30 +++++++++++++ .../Calendar/prototype/inLeapYear/string.js | 45 +++++++++++++++++++ .../prototype/inLeapYear/year-month.js | 30 +++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js new file mode 100644 index 00000000000..a1c85940859 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainDateTime object + and return true or false that year is leap year. + and return Array of the same content. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js new file mode 100644 index 00000000000..9409cb60418 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainDate object + and return true or false that year is leap year. + and return Array of the same content. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1995, 7, 15))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(1996, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1997, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1998, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1999, 7, 15))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(2000, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2001, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2002, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2003, 7, 15))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(2004, 7, 15))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2005, 7, 15))); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js new file mode 100644 index 00000000000..28f36e4c939 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js @@ -0,0 +1,45 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: Temporal.Calendar.prototype.inLeapYear will take an ISO8601 string + and return true or false that year is leap year. + and return Array of the same content. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(false, cal.inLeapYear("2019-03-18")); +assert.sameValue(true, cal.inLeapYear("2020-03-18")); +assert.sameValue(false, cal.inLeapYear("2021-03-18")); +assert.sameValue(false, cal.inLeapYear("2022-03-18")); +assert.sameValue(false, cal.inLeapYear("2023-03-18")); +assert.sameValue(true, cal.inLeapYear("2024-03-18")); +assert.sameValue(false, cal.inLeapYear("2025-03-18")); +assert.sameValue(false, cal.inLeapYear("2026-03-18")); + +assert.sameValue(false, cal.inLeapYear("2019-03-18T13:00:00Z")); +assert.sameValue(true, cal.inLeapYear("2020-12-31T23:59:59Z")); +assert.sameValue(false, cal.inLeapYear("2021-03-18T13:00:00Z")); +assert.sameValue(false, cal.inLeapYear("2022-03-18T13:00:00Z")); +assert.sameValue(false, cal.inLeapYear("2023-03-18T13:00:00Z")); +assert.sameValue(true, cal.inLeapYear("2024-03-18T13:00:00Z")); +assert.sameValue(false, cal.inLeapYear("2025-01-01T00:00:00Z")); +assert.sameValue(false, cal.inLeapYear("2026-03-18T13:00:00Z")); + +assert.sameValue(false, cal.inLeapYear("2019-03")); +assert.sameValue(true, cal.inLeapYear("2020-03")); +assert.sameValue(false, cal.inLeapYear("2021-03")); +assert.sameValue(false, cal.inLeapYear("2022-03")); +assert.sameValue(false, cal.inLeapYear("2023-03")); +assert.sameValue(true, cal.inLeapYear("2024-03")); +assert.sameValue(false, cal.inLeapYear("2025-03")); +assert.sameValue(false, cal.inLeapYear("2026-03")); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js new file mode 100644 index 00000000000..abeb0361a20 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainYearMonth object + and return true or false that year is leap year. + and return Array of the same content. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1995, 7))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(1996, 2))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1997, 1))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1998, 7))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1999, 7))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(2000, 12))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2001, 3))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2002, 7))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2003, 12))); +assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(2004, 7))); +assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2005, 1))); From cafc0e451b8a24fa1e2774b52405431ad834e14f Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 20 Jul 2021 01:46:06 -0700 Subject: [PATCH 2/3] Fix wrong expectation and add new throws --- .../inLeapYear/string-throw-range-error.js | 29 +++++++++++++++++++ .../Calendar/prototype/inLeapYear/string.js | 9 ------ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js new file mode 100644 index 00000000000..2a974380037 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: Temporal.Calendar.prototype.inLeapYear throw RangeError while ISO8601 string is not a date. + and return true or false that year is leap year. + and return Array of the same content. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.inLeapYear("2019-03"), + "Invalid time value"); +assert.throws(RangeError, () => cal.inLeapYear("--03-04"), + "Invalid time value"); +assert.throws(RangeError, () => cal.inLeapYear("P1Y"), + "Invalid time value"); +assert.throws(RangeError, () => cal.inLeapYear("+P1Y"), + "Invalid time value"); +assert.throws(RangeError, () => cal.inLeapYear("-P1Y"), + "Invalid time value"); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js index 28f36e4c939..c1836aa5847 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js @@ -34,12 +34,3 @@ assert.sameValue(false, cal.inLeapYear("2023-03-18T13:00:00Z")); assert.sameValue(true, cal.inLeapYear("2024-03-18T13:00:00Z")); assert.sameValue(false, cal.inLeapYear("2025-01-01T00:00:00Z")); assert.sameValue(false, cal.inLeapYear("2026-03-18T13:00:00Z")); - -assert.sameValue(false, cal.inLeapYear("2019-03")); -assert.sameValue(true, cal.inLeapYear("2020-03")); -assert.sameValue(false, cal.inLeapYear("2021-03")); -assert.sameValue(false, cal.inLeapYear("2022-03")); -assert.sameValue(false, cal.inLeapYear("2023-03")); -assert.sameValue(true, cal.inLeapYear("2024-03")); -assert.sameValue(false, cal.inLeapYear("2025-03")); -assert.sameValue(false, cal.inLeapYear("2026-03")); From 3a650011996fa6b052d267b8dcc6dde8b4ec5b8b Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 5 Aug 2021 16:25:06 -0700 Subject: [PATCH 3/3] Add tests and correct actual/expect order --- .../prototype/inLeapYear/plain-date-time.js | 50 ++++++++++++------- .../prototype/inLeapYear/plain-date.js | 50 ++++++++++++------- .../inLeapYear/string-throw-range-error.js | 18 ++----- .../Calendar/prototype/inLeapYear/string.js | 39 +++++++-------- .../throw-range-error-ToTemporalDate.js | 17 +++++++ .../throw-type-error-RequireInternalSlot.js | 15 ++++++ .../prototype/inLeapYear/year-month.js | 50 ++++++++++++------- 7 files changed, 151 insertions(+), 88 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-type-error-RequireInternalSlot.js diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js index a1c85940859..d72a2a67e2f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date-time.js @@ -1,30 +1,46 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. - /*--- esid: sec-temporal.calendar.prototype.inleapyear description: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainDateTime object and return true or false that year is leap year. - and return Array of the same content. info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); +let dt = new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), true); + +dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), true); + +dt = new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); + +dt = new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), true); + +dt = new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13); +assert.sameValue(cal.inLeapYear(dt), false); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js index 9409cb60418..9723cb48222 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/plain-date.js @@ -1,30 +1,44 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. - /*--- esid: sec-temporal.calendar.prototype.inleapyear description: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainDate object and return true or false that year is leap year. - and return Array of the same content. info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1995, 7, 15))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(1996, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1997, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1998, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(1999, 7, 15))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(2000, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2001, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2002, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2003, 7, 15))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainDate(2004, 7, 15))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainDate(2005, 7, 15))); +let d = new Temporal.PlainDate(1995, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(1996, 7, 15); +assert.sameValue(cal.inLeapYear(d), true); + +d = new Temporal.PlainDate(1997, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(1998, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(1999, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(2000, 7, 15); +assert.sameValue(cal.inLeapYear(d), true); + +d = new Temporal.PlainDate(2001, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(2002, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(2003, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); + +d = new Temporal.PlainDate(2004, 7, 15); +assert.sameValue(cal.inLeapYear(d), true); + +d = new Temporal.PlainDate(2005, 7, 15); +assert.sameValue(cal.inLeapYear(d), false); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js index 2a974380037..b72cb10c4d3 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string-throw-range-error.js @@ -1,29 +1,19 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. - /*--- esid: sec-temporal.calendar.prototype.inleapyear description: Temporal.Calendar.prototype.inLeapYear throw RangeError while ISO8601 string is not a date. - and return true or false that year is leap year. - and return Array of the same content. info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.throws(RangeError, () => cal.inLeapYear("2019-03"), - "Invalid time value"); -assert.throws(RangeError, () => cal.inLeapYear("--03-04"), - "Invalid time value"); assert.throws(RangeError, () => cal.inLeapYear("P1Y"), - "Invalid time value"); + "Duration string should throw RangeError"); assert.throws(RangeError, () => cal.inLeapYear("+P1Y"), - "Invalid time value"); + "Duration string should throw RangeError"); assert.throws(RangeError, () => cal.inLeapYear("-P1Y"), - "Invalid time value"); + "Duration string should throw RangeError"); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js index c1836aa5847..01889ec5c94 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/string.js @@ -1,36 +1,31 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. - /*--- esid: sec-temporal.calendar.prototype.inleapyear description: Temporal.Calendar.prototype.inLeapYear will take an ISO8601 string and return true or false that year is leap year. - and return Array of the same content. info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(false, cal.inLeapYear("2019-03-18")); -assert.sameValue(true, cal.inLeapYear("2020-03-18")); -assert.sameValue(false, cal.inLeapYear("2021-03-18")); -assert.sameValue(false, cal.inLeapYear("2022-03-18")); -assert.sameValue(false, cal.inLeapYear("2023-03-18")); -assert.sameValue(true, cal.inLeapYear("2024-03-18")); -assert.sameValue(false, cal.inLeapYear("2025-03-18")); -assert.sameValue(false, cal.inLeapYear("2026-03-18")); +assert.sameValue(cal.inLeapYear("2019-03-18"), false); +assert.sameValue(cal.inLeapYear("2020-03-18"), true); +assert.sameValue(cal.inLeapYear("2021-03-18"), false); +assert.sameValue(cal.inLeapYear("2022-03-18"), false); +assert.sameValue(cal.inLeapYear("2023-03-18"), false); +assert.sameValue(cal.inLeapYear("2024-03-18"), true); +assert.sameValue(cal.inLeapYear("2025-03-18"), false); +assert.sameValue(cal.inLeapYear("2026-03-18"), false); -assert.sameValue(false, cal.inLeapYear("2019-03-18T13:00:00Z")); -assert.sameValue(true, cal.inLeapYear("2020-12-31T23:59:59Z")); -assert.sameValue(false, cal.inLeapYear("2021-03-18T13:00:00Z")); -assert.sameValue(false, cal.inLeapYear("2022-03-18T13:00:00Z")); -assert.sameValue(false, cal.inLeapYear("2023-03-18T13:00:00Z")); -assert.sameValue(true, cal.inLeapYear("2024-03-18T13:00:00Z")); -assert.sameValue(false, cal.inLeapYear("2025-01-01T00:00:00Z")); -assert.sameValue(false, cal.inLeapYear("2026-03-18T13:00:00Z")); +assert.sameValue(cal.inLeapYear("2019-03-18T13:00:00Z"), false); +assert.sameValue(cal.inLeapYear("2020-12-31T23:59:59Z"), true); +assert.sameValue(cal.inLeapYear("2021-03-18T13:00:00Z"), false); +assert.sameValue(cal.inLeapYear("2022-03-18T13:00:00Z"), false); +assert.sameValue(cal.inLeapYear("2023-03-18T13:00:00Z"), false); +assert.sameValue(cal.inLeapYear("2024-03-18T13:00:00Z"), true); +assert.sameValue(cal.inLeapYear("2025-01-01T00:00:00Z"), false); +assert.sameValue(cal.inLeapYear("2026-03-18T13:00:00Z"), false); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-range-error-ToTemporalDate.js new file mode 100644 index 00000000000..053702e4304 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-range-error-ToTemporalDate.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.calendar.prototype.inLeapYear +description: Temporal.Calendar.prototype.inLeapYear throws RangeError on + ToTemporalDate when temporalDateLike is invalid string. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike + does not have an [[InitializedTemporalDate]] or + [[InitializedTemporalYearMonth]] internal slot, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.inLeapYear("invalid string"), + "Throw RangeError if temporalDateLike is invalid"); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-type-error-RequireInternalSlot.js new file mode 100644 index 00000000000..5595f660416 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/throw-type-error-RequireInternalSlot.js @@ -0,0 +1,15 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-temporal.calendar.prototype.inLeapYear +description: Temporal.Calendar.prototype.inLeapYear throws TypeError on + RequireInternalSlot if object has no internal slot. +info: | + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let badCal = { inLeapYear: cal.inLeapYear } +assert.throws(TypeError, () => badCal.inLeapYear("2021-03-04"), + "Throw TypeError if there are no internal slot"); diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js index abeb0361a20..5d368cc12d0 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-month.js @@ -1,30 +1,46 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. - /*--- esid: sec-temporal.calendar.prototype.inleapyear description: Temporal.Calendar.prototype.inLeapYear will take Temporal.PlainYearMonth object and return true or false that year is leap year. - and return Array of the same content. info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return ! IsISOLeapYear(temporalDateLike.[[ISOYear]]). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1995, 7))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(1996, 2))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1997, 1))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1998, 7))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(1999, 7))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(2000, 12))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2001, 3))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2002, 7))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2003, 12))); -assert.sameValue(true, cal.inLeapYear(new Temporal.PlainYearMonth(2004, 7))); -assert.sameValue(false, cal.inLeapYear(new Temporal.PlainYearMonth(2005, 1))); +let ym = new Temporal.PlainYearMonth(1995, 7); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(1996, 2); +assert.sameValue(cal.inLeapYear(ym), true); + +ym = new Temporal.PlainYearMonth(1997, 1); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(1998, 7); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(1999, 11); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(2000, 12); +assert.sameValue(cal.inLeapYear(ym), true); + +ym = new Temporal.PlainYearMonth(2001, 3); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(2002, 7); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(2003, 12); +assert.sameValue(cal.inLeapYear(ym), false); + +ym = new Temporal.PlainYearMonth(2004, 7); +assert.sameValue(cal.inLeapYear(ym), true); + +ym = new Temporal.PlainYearMonth(2005, 1); +assert.sameValue(cal.inLeapYear(ym), false);