From 124baf8ec50325f1644270309fbc96ff82d2952f Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Sat, 17 Jul 2021 02:37:56 -0700 Subject: [PATCH 1/5] Add Temporal.Calendar.prototype.daysIn* tests. --- .../days-in-month/plain-date-time.js | 35 +++++++++++++ .../prototype/days-in-month/plain-date.js | 35 +++++++++++++ .../prototype/days-in-month/string.js | 34 +++++++++++++ .../Calendar/prototype/days-in-week/simple.js | 20 ++++++++ .../prototype/days-in-year/plain-date-time.js | 29 +++++++++++ .../prototype/days-in-year/plain-date.js | 29 +++++++++++ .../Calendar/prototype/days-in-year/string.js | 50 +++++++++++++++++++ 7 files changed, 232 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date-time.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date-time.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date-time.js new file mode 100644 index 00000000000..8d99c84bb52 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date-time.js @@ -0,0 +1,35 @@ +// 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.daysinmonth +description: Temporal.Calendar.prototype.daysInMonth will take Temporal.PlainDateTime object + and return the number of days in that month. + 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 slots, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13))); +// leap year +assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13))); +assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13))); +// non leap year +assert.sameValue(28, cal.daysInMonth(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13))); diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date.js new file mode 100644 index 00000000000..5453a298fde --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date.js @@ -0,0 +1,35 @@ +// 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.daysinmonth +description: Temporal.Calendar.prototype.daysInMonth will take Temporal.PlainDate object + and return the number of days in that month. + 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 slots, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 1, 15))); +// leap year +assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDate(2020, 2, 15))); +assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDate(2000, 2, 15))); +// non-leap year +assert.sameValue(28, cal.daysInMonth(new Temporal.PlainDate(2021, 2, 15))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 3, 15))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 4, 15))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 5, 15))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 6, 15))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 7, 15))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 8, 15))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 9, 15))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 10, 15))); +assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 11, 15))); +assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 12, 15))); diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js b/test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js new file mode 100644 index 00000000000..a4eb883b5e7 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js @@ -0,0 +1,34 @@ +// 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.daysinmonth +description: Temporal.Calendar.prototype.daysInMonth will take ISO8601 string + and return the number of days in that month. + 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 slots, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(31, cal.daysInMonth("2019-01-18")); +// leap year +assert.sameValue(29, cal.daysInMonth("2020-02-18")); +// non leap +assert.sameValue(28, cal.daysInMonth("2019-02-18")); +assert.sameValue(31, cal.daysInMonth("2019-03-18")); +assert.sameValue(30, cal.daysInMonth("2019-04-18")); +assert.sameValue(31, cal.daysInMonth("2019-05-18")); +assert.sameValue(30, cal.daysInMonth("2019-06-18")); +assert.sameValue(31, cal.daysInMonth("2019-07-18")); +assert.sameValue(31, cal.daysInMonth("2019-08-18")); +assert.sameValue(30, cal.daysInMonth("2019-09-18")); +assert.sameValue(31, cal.daysInMonth("2019-10-18")); +assert.sameValue(30, cal.daysInMonth("2019-11-18")); +assert.sameValue(31, cal.daysInMonth("2019-12-18")); diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js b/test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js new file mode 100644 index 00000000000..26730675982 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js @@ -0,0 +1,20 @@ +// 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.daysinweeks +description: Temporal.Calendar.prototype.daysInWeek will take different kind of object + and return 7. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 7𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(7, cal.daysInWeek(new Temporal.PlainDate(2021, 7, 15))); +assert.sameValue(7, cal.daysInWeek(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(7, cal.daysInWeek("2019-03-18")); diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date-time.js new file mode 100644 index 00000000000..8eed6719a3f --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date-time.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.daysinyear +description: Temporal.Calendar.prototype.daysInYear will take PlainDateTime and return + the number of days in a year. +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 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date.js new file mode 100644 index 00000000000..f3b4905819d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date.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.daysinyear +description: Temporal.Calendar.prototype.daysInYear will take PlainDate and return + the number of days in a year. +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 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1995, 7, 15))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(1996, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1997, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1998, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1999, 7, 15))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2000, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2001, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2002, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2003, 7, 15))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2004, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2005, 7, 15))); diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js b/test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js new file mode 100644 index 00000000000..0af2ec2a1b9 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js @@ -0,0 +1,50 @@ +// 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.daysinyear +description: Temporal.Calendar.prototype.daysInYear will take PlainDate and return + the number of days in a year. +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 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1995, 7, 15))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(1996, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1997, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1998, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1999, 7, 15))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2000, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2001, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2002, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2003, 7, 15))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2004, 7, 15))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2005, 7, 15))); + +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); +assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); +assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); + +assert.sameValue(365, cal.daysInYear("2019-03-18")); +assert.sameValue(366, cal.daysInYear("2020-03-18")); +assert.sameValue(365, cal.daysInYear("2021-03-18")); +assert.sameValue(365, cal.daysInYear("2022-03-18")); +assert.sameValue(365, cal.daysInYear("2023-03-18")); +assert.sameValue(366, cal.daysInYear("2024-03-18")); +assert.sameValue(365, cal.daysInYear("2025-03-18")); +assert.sameValue(365, cal.daysInYear("2026-03-18")); From 9ecebe68c3861162ebd7ad7508fd6f4d1c383b5e Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 19 Jul 2021 11:21:27 -0700 Subject: [PATCH 2/5] fix directory name --- .../prototype/{days-in-month => daysInMonth}/plain-date-time.js | 0 .../prototype/{days-in-month => daysInMonth}/plain-date.js | 0 .../Calendar/prototype/{days-in-month => daysInMonth}/string.js | 0 .../Calendar/prototype/{days-in-week => daysInWeek}/simple.js | 0 .../prototype/{days-in-year => daysInYear}/plain-date-time.js | 0 .../Calendar/prototype/{days-in-year => daysInYear}/plain-date.js | 0 .../Calendar/prototype/{days-in-year => daysInYear}/string.js | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename test/built-ins/Temporal/Calendar/prototype/{days-in-month => daysInMonth}/plain-date-time.js (100%) rename test/built-ins/Temporal/Calendar/prototype/{days-in-month => daysInMonth}/plain-date.js (100%) rename test/built-ins/Temporal/Calendar/prototype/{days-in-month => daysInMonth}/string.js (100%) rename test/built-ins/Temporal/Calendar/prototype/{days-in-week => daysInWeek}/simple.js (100%) rename test/built-ins/Temporal/Calendar/prototype/{days-in-year => daysInYear}/plain-date-time.js (100%) rename test/built-ins/Temporal/Calendar/prototype/{days-in-year => daysInYear}/plain-date.js (100%) rename test/built-ins/Temporal/Calendar/prototype/{days-in-year => daysInYear}/string.js (100%) diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date-time.js rename to test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-month/plain-date.js rename to test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js rename to test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/simple.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js rename to test/built-ins/Temporal/Calendar/prototype/daysInWeek/simple.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date-time.js rename to test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-year/plain-date.js rename to test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js diff --git a/test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js similarity index 100% rename from test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js rename to test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js From 008d7d0b78697e58b109a53f84c946b9f12a4151 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 19 Jul 2021 14:30:08 -0700 Subject: [PATCH 3/5] Remove incorrect lines --- .../Temporal/Calendar/prototype/daysInMonth/plain-date-time.js | 1 - .../Temporal/Calendar/prototype/daysInMonth/plain-date.js | 1 - test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js | 1 - 3 files changed, 3 deletions(-) diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js index 8d99c84bb52..ca8cb07d2ff 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js @@ -5,7 +5,6 @@ esid: sec-temporal.calendar.prototype.daysinmonth description: Temporal.Calendar.prototype.daysInMonth will take Temporal.PlainDateTime object and return the number of days in that month. - and return Array of the same content. info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js index 5453a298fde..2b13e12f3e0 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js @@ -5,7 +5,6 @@ esid: sec-temporal.calendar.prototype.daysinmonth description: Temporal.Calendar.prototype.daysInMonth will take Temporal.PlainDate object and return the number of days in that month. - and return Array of the same content. info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js index a4eb883b5e7..70f96d3b532 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js @@ -5,7 +5,6 @@ esid: sec-temporal.calendar.prototype.daysinmonth description: Temporal.Calendar.prototype.daysInMonth will take ISO8601 string and return the number of days in that month. - and return Array of the same content. info: | 1. Let calendar be the this value. 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). From 7943198b1d5c68dd95a233fba50c42541b526bf7 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 5 Aug 2021 15:45:43 -0700 Subject: [PATCH 4/5] Split the test and add more tests --- .../prototype/daysInMonth/plain-date-time.js | 60 ++++++++++++------ .../prototype/daysInMonth/plain-date.js | 62 ++++++++++++------- .../Calendar/prototype/daysInMonth/string.js | 10 ++- .../Calendar/prototype/daysInWeek/simple.js | 20 ------ .../prototype/daysInYear/plain-date-time.js | 49 ++++++++++----- .../prototype/daysInYear/plain-date.js | 49 ++++++++++----- .../Calendar/prototype/daysInYear/string.js | 30 +-------- 7 files changed, 152 insertions(+), 128 deletions(-) delete mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/simple.js diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js index ca8cb07d2ff..c28381daf0e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js @@ -1,34 +1,56 @@ // 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.daysinmonth description: Temporal.Calendar.prototype.daysInMonth will take Temporal.PlainDateTime object and return the number of days in that month. 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 slots, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13))); +let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); + // leap year -assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13))); -assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13))); +dt = new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13); +assert.sameValue(29, cal.daysInMonth(dt)); +dt = new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13); +assert.sameValue(29, cal.daysInMonth(dt)); + // non leap year -assert.sameValue(28, cal.daysInMonth(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13))); +dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13); +assert.sameValue(28, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13); +assert.sameValue(30, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13); +assert.sameValue(30, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13); +assert.sameValue(30, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13); +assert.sameValue(30, cal.daysInMonth(dt)); + +dt = new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13); +assert.sameValue(31, cal.daysInMonth(dt)); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js index 2b13e12f3e0..b585e2207ee 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js @@ -1,34 +1,54 @@ // 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.daysinmonth description: Temporal.Calendar.prototype.daysInMonth will take Temporal.PlainDate object and return the number of days in that month. 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 slots, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 1, 15))); -// leap year -assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDate(2020, 2, 15))); -assert.sameValue(29, cal.daysInMonth(new Temporal.PlainDate(2000, 2, 15))); +let d = new Temporal.PlainDate(2021, 1, 15); +assert.sameValue(31, cal.daysInMonth(d)); + // non-leap year -assert.sameValue(28, cal.daysInMonth(new Temporal.PlainDate(2021, 2, 15))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 3, 15))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 4, 15))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 5, 15))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 6, 15))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 7, 15))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 8, 15))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 9, 15))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 10, 15))); -assert.sameValue(30, cal.daysInMonth(new Temporal.PlainDate(2021, 11, 15))); -assert.sameValue(31, cal.daysInMonth(new Temporal.PlainDate(2021, 12, 15))); +d = new Temporal.PlainDate(2021, 2, 15); +assert.sameValue(28, cal.daysInMonth(d)); + +// leap year +d = new Temporal.PlainDate(2020, 2, 15); +assert.sameValue(29, cal.daysInMonth(d)); +d = new Temporal.PlainDate(2000, 2, 15); +assert.sameValue(29, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 3, 15); +assert.sameValue(31, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 4, 15); +assert.sameValue(30, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 5, 15); +assert.sameValue(31, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 6, 15); +assert.sameValue(30, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 7, 15); +assert.sameValue(31, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 8, 15); +assert.sameValue(31, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 9, 15); +assert.sameValue(30, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 10, 15); +assert.sameValue(31, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 11, 15); +assert.sameValue(30, cal.daysInMonth(d)); + +d = new Temporal.PlainDate(2021, 12, 15); +assert.sameValue(31, cal.daysInMonth(d)); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js index 70f96d3b532..b2b4ac096dc 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js @@ -1,16 +1,14 @@ // 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.daysinmonth description: Temporal.Calendar.prototype.daysInMonth will take ISO8601 string and return the number of days in that month. 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 slots, then - a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have + an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal + slots, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). features: [Temporal] ---*/ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/simple.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/simple.js deleted file mode 100644 index 26730675982..00000000000 --- a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/simple.js +++ /dev/null @@ -1,20 +0,0 @@ -// 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.daysinweeks -description: Temporal.Calendar.prototype.daysInWeek will take different kind of object - and return 7. -info: | - 1. Let calendar be the this value. - 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). - 3. Assert: calendar.[[Identifier]] is "iso8601". - 4. Perform ? ToTemporalDate(temporalDateLike). - 5. Return 7𝔽. -features: [Temporal] ----*/ -let cal = new Temporal.Calendar("iso8601"); - -assert.sameValue(7, cal.daysInWeek(new Temporal.PlainDate(2021, 7, 15))); -assert.sameValue(7, cal.daysInWeek(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); -assert.sameValue(7, cal.daysInWeek("2019-03-18")); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js index 8eed6719a3f..91d3d432a8f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js @@ -1,29 +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.daysinyear description: Temporal.Calendar.prototype.daysInYear will take PlainDateTime and return the number of days in a year. 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 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); +let dt = new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13); +assert.sameValue(366, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13); +assert.sameValue(366, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13); +assert.sameValue(366, cal.daysInYear(dt)); + +dt = new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13); +assert.sameValue(365, cal.daysInYear(dt)); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js index f3b4905819d..2805d9e872a 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js @@ -1,29 +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.daysinyear description: Temporal.Calendar.prototype.daysInYear will take PlainDate and return the number of days in a year. 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 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1995, 7, 15))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(1996, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1997, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1998, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1999, 7, 15))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2000, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2001, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2002, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2003, 7, 15))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2004, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2005, 7, 15))); +let d = new Temporal.PlainDate(1995, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(1996, 7, 15); +assert.sameValue(366, cal.daysInYear(d)); + +d = new Temporal.PlainDate(1997, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(1998, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(1999, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(2000, 7, 15); +assert.sameValue(366, cal.daysInYear(d)); + +d = new Temporal.PlainDate(2001, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(2002, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(2003, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); + +d = new Temporal.PlainDate(2004, 7, 15); +assert.sameValue(366, cal.daysInYear(d)); + +d = new Temporal.PlainDate(2005, 7, 15); +assert.sameValue(365, cal.daysInYear(d)); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js index 0af2ec2a1b9..8e1bfb3d4d6 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js @@ -1,45 +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.daysinyear description: Temporal.Calendar.prototype.daysInYear will take PlainDate and return the number of days in a year. 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 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1995, 7, 15))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(1996, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1997, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1998, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(1999, 7, 15))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2000, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2001, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2002, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2003, 7, 15))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDate(2004, 7, 15))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDate(2005, 7, 15))); - -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13))); -assert.sameValue(366, cal.daysInYear(new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13))); -assert.sameValue(365, cal.daysInYear(new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13))); - assert.sameValue(365, cal.daysInYear("2019-03-18")); assert.sameValue(366, cal.daysInYear("2020-03-18")); assert.sameValue(365, cal.daysInYear("2021-03-18")); From 44bd73e7c1d6c117100e8f23f435e61c83b11644 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Thu, 5 Aug 2021 15:57:57 -0700 Subject: [PATCH 5/5] Add more tests --- .../prototype/daysInMonth/plain-date-time.js | 28 +++++++++---------- .../prototype/daysInMonth/plain-date.js | 28 +++++++++---------- .../Calendar/prototype/daysInMonth/string.js | 26 ++++++++--------- .../throw-range-error-ToTemporalDate.js | 17 +++++++++++ .../throw-type-error-RequireInternalSlot.js | 15 ++++++++++ .../prototype/daysInWeek/date-time.js | 14 ++++++++++ .../Calendar/prototype/daysInWeek/date.js | 13 +++++++++ .../Calendar/prototype/daysInWeek/string.js | 13 +++++++++ .../throw-range-error-ToTemporalDate.js | 14 ++++++++++ .../throw-type-error-RequireInternalSlot.js | 15 ++++++++++ .../prototype/daysInYear/plain-date-time.js | 22 +++++++-------- .../prototype/daysInYear/plain-date.js | 22 +++++++-------- .../Calendar/prototype/daysInYear/string.js | 16 +++++------ .../throw-range-error-ToTemporalDate.js | 17 +++++++++++ .../throw-type-error-RequireInternalSlot.js | 15 ++++++++++ 15 files changed, 204 insertions(+), 71 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInMonth/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInMonth/throw-type-error-RequireInternalSlot.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/date-time.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/date.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/string.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-type-error-RequireInternalSlot.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInYear/throw-range-error-ToTemporalDate.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInYear/throw-type-error-RequireInternalSlot.js diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js index c28381daf0e..4c31648a6ec 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js @@ -13,44 +13,44 @@ features: [Temporal] let cal = new Temporal.Calendar("iso8601"); let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); // leap year dt = new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13); -assert.sameValue(29, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 29); dt = new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13); -assert.sameValue(29, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 29); // non leap year dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13); -assert.sameValue(28, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 28); dt = new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); dt = new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13); -assert.sameValue(30, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 30); dt = new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); dt = new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13); -assert.sameValue(30, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 30); dt = new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); dt = new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13); -assert.sameValue(30, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 30); dt = new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); dt = new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13); -assert.sameValue(30, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 30); dt = new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13); -assert.sameValue(31, cal.daysInMonth(dt)); +assert.sameValue(cal.daysInMonth(dt), 31); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js index b585e2207ee..32df3782424 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js @@ -11,44 +11,44 @@ features: [Temporal] let cal = new Temporal.Calendar("iso8601"); let d = new Temporal.PlainDate(2021, 1, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); // non-leap year d = new Temporal.PlainDate(2021, 2, 15); -assert.sameValue(28, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 28); // leap year d = new Temporal.PlainDate(2020, 2, 15); -assert.sameValue(29, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 29); d = new Temporal.PlainDate(2000, 2, 15); -assert.sameValue(29, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 29); d = new Temporal.PlainDate(2021, 3, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); d = new Temporal.PlainDate(2021, 4, 15); -assert.sameValue(30, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 30); d = new Temporal.PlainDate(2021, 5, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); d = new Temporal.PlainDate(2021, 6, 15); -assert.sameValue(30, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 30); d = new Temporal.PlainDate(2021, 7, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); d = new Temporal.PlainDate(2021, 8, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); d = new Temporal.PlainDate(2021, 9, 15); -assert.sameValue(30, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 30); d = new Temporal.PlainDate(2021, 10, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); d = new Temporal.PlainDate(2021, 11, 15); -assert.sameValue(30, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 30); d = new Temporal.PlainDate(2021, 12, 15); -assert.sameValue(31, cal.daysInMonth(d)); +assert.sameValue(cal.daysInMonth(d), 31); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js index b2b4ac096dc..e3033dffc56 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js @@ -14,18 +14,18 @@ features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(31, cal.daysInMonth("2019-01-18")); +assert.sameValue(cal.daysInMonth("2019-01-18"), 31); // leap year -assert.sameValue(29, cal.daysInMonth("2020-02-18")); +assert.sameValue(cal.daysInMonth("2020-02-18"), 29); // non leap -assert.sameValue(28, cal.daysInMonth("2019-02-18")); -assert.sameValue(31, cal.daysInMonth("2019-03-18")); -assert.sameValue(30, cal.daysInMonth("2019-04-18")); -assert.sameValue(31, cal.daysInMonth("2019-05-18")); -assert.sameValue(30, cal.daysInMonth("2019-06-18")); -assert.sameValue(31, cal.daysInMonth("2019-07-18")); -assert.sameValue(31, cal.daysInMonth("2019-08-18")); -assert.sameValue(30, cal.daysInMonth("2019-09-18")); -assert.sameValue(31, cal.daysInMonth("2019-10-18")); -assert.sameValue(30, cal.daysInMonth("2019-11-18")); -assert.sameValue(31, cal.daysInMonth("2019-12-18")); +assert.sameValue(cal.daysInMonth("2019-02-18"), 28); +assert.sameValue(cal.daysInMonth("2019-03-18"), 31); +assert.sameValue(cal.daysInMonth("2019-04-18"), 30); +assert.sameValue(cal.daysInMonth("2019-05-18"), 31); +assert.sameValue(cal.daysInMonth("2019-06-18"), 30); +assert.sameValue(cal.daysInMonth("2019-07-18"), 31); +assert.sameValue(cal.daysInMonth("2019-08-18"), 31); +assert.sameValue(cal.daysInMonth("2019-09-18"), 30); +assert.sameValue(cal.daysInMonth("2019-10-18"), 31); +assert.sameValue(cal.daysInMonth("2019-11-18"), 30); +assert.sameValue(cal.daysInMonth("2019-12-18"), 31); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/throw-range-error-ToTemporalDate.js new file mode 100644 index 00000000000..21de3cfec37 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/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.daysInMonth +description: Temporal.Calendar.prototype.daysInMonth 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 + slots, then + a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.daysInMonth("invalid string"), + "Throw RangeError if temporalDateLike is invalid"); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/throw-type-error-RequireInternalSlot.js new file mode 100644 index 00000000000..d932bd72ecd --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/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.daysInMonth +description: Temporal.Calendar.prototype.daysInMonth throws TypeError + when the internal lot is not presented. +info: | + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let badCal = { daysInMonth: cal.daysInMonth } +assert.throws(TypeError, () => badCal.daysInMonth("2021-03-04"), + "Throw TypeError if no internal slot"); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/date-time.js new file mode 100644 index 00000000000..6dc3454f55c --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/date-time.js @@ -0,0 +1,14 @@ +// 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.daysinweeks +description: Temporal.Calendar.prototype.daysInWeek will take PlainDateTime and return 7. +info: | + 4. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 7𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInWeek(dt), 7); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/date.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/date.js new file mode 100644 index 00000000000..cf7333dbed4 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/date.js @@ -0,0 +1,13 @@ +// 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.daysinweeks +description: Temporal.Calendar.prototype.daysInWeek will take PlainDate and return 7. +info: | + 5. Return 7𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let d = new Temporal.PlainDate(2021, 7, 15); +assert.sameValue(cal.daysInWeek(d), 7); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/string.js new file mode 100644 index 00000000000..4053d944227 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/string.js @@ -0,0 +1,13 @@ +// 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.daysinweeks +description: Temporal.Calendar.prototype.daysInWeek will take valid ISO8601 string + and return 7. +info: | + 4. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 7𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); +assert.sameValue(cal.daysInWeek("2019-03-18"), 7); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-range-error-ToTemporalDate.js new file mode 100644 index 00000000000..1a16d91d5ba --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-range-error-ToTemporalDate.js @@ -0,0 +1,14 @@ +// 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.daysInWeek +description: Temporal.Calendar.prototype.daysInWeek throws RangeError on + ToTemporalDate when temporalDateLike is invalid string. +info: | + 4. Let temporalDate be ? ToTemporalDate(temporalDateLike). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.daysInWeek("invalid string"), + "Throw RangeError if temporalDateLike is invalid"); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/throw-type-error-RequireInternalSlot.js new file mode 100644 index 00000000000..faf4321b3ce --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/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.daysInWeek +description: Temporal.Calendar.prototype.daysInWeek throws TypeError + when the internal lot is not presented. +info: | + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let badCal = { daysInWeek: cal.daysInWeek } +assert.throws(TypeError, () => badCal.daysInWeek("2021-03-04"), + "Throw TypeError if no internal slot"); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js index 91d3d432a8f..d2909b40f7d 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js @@ -13,34 +13,34 @@ features: [Temporal] let cal = new Temporal.Calendar("iso8601"); let dt = new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13); -assert.sameValue(366, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 366); dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13); -assert.sameValue(366, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 366); dt = new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); dt = new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13); -assert.sameValue(366, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 366); dt = new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13); -assert.sameValue(365, cal.daysInYear(dt)); +assert.sameValue(cal.daysInYear(dt), 365); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js index 2805d9e872a..7025f271c66 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js @@ -11,34 +11,34 @@ features: [Temporal] let cal = new Temporal.Calendar("iso8601"); let d = new Temporal.PlainDate(1995, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(1996, 7, 15); -assert.sameValue(366, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 366); d = new Temporal.PlainDate(1997, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(1998, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(1999, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(2000, 7, 15); -assert.sameValue(366, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 366); d = new Temporal.PlainDate(2001, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(2002, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(2003, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); d = new Temporal.PlainDate(2004, 7, 15); -assert.sameValue(366, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 366); d = new Temporal.PlainDate(2005, 7, 15); -assert.sameValue(365, cal.daysInYear(d)); +assert.sameValue(cal.daysInYear(d), 365); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js index 8e1bfb3d4d6..f7dff2790b4 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js @@ -12,11 +12,11 @@ features: [Temporal] ---*/ let cal = new Temporal.Calendar("iso8601"); -assert.sameValue(365, cal.daysInYear("2019-03-18")); -assert.sameValue(366, cal.daysInYear("2020-03-18")); -assert.sameValue(365, cal.daysInYear("2021-03-18")); -assert.sameValue(365, cal.daysInYear("2022-03-18")); -assert.sameValue(365, cal.daysInYear("2023-03-18")); -assert.sameValue(366, cal.daysInYear("2024-03-18")); -assert.sameValue(365, cal.daysInYear("2025-03-18")); -assert.sameValue(365, cal.daysInYear("2026-03-18")); +assert.sameValue(cal.daysInYear("2019-03-18"), 365); +assert.sameValue(cal.daysInYear("2020-03-18"), 366); +assert.sameValue(cal.daysInYear("2021-03-18"), 365); +assert.sameValue(cal.daysInYear("2022-03-18"), 365); +assert.sameValue(cal.daysInYear("2023-03-18"), 365); +assert.sameValue(cal.daysInYear("2024-03-18"), 366); +assert.sameValue(cal.daysInYear("2025-03-18"), 365); +assert.sameValue(cal.daysInYear("2026-03-18"), 365); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/throw-range-error-ToTemporalDate.js new file mode 100644 index 00000000000..2128492884b --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/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.daysInYear +description: Temporal.Calendar.prototype.daysInYear 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.daysInYear("invalid string"), + "Throw RangeError if temporalDateLike is invalid"); diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/throw-type-error-RequireInternalSlot.js new file mode 100644 index 00000000000..1c113d8dec1 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/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.daysInYear +description: Temporal.Calendar.prototype.daysInYear throws TypeError + when the internal lot is not presented. +info: | + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let badCal = { daysInYear: cal.daysInYear } +assert.throws(TypeError, () => badCal.daysInYear("2021-03-04"), + "Throw TypeError if no internal slot");