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 new file mode 100644 index 00000000000..4c31648a6ec --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date-time.js @@ -0,0 +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: | + 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"); + +let dt = new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 31); + +// leap year +dt = new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 29); +dt = new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 29); + +// non leap year +dt = new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 28); + +dt = new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 31); + +dt = new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 30); + +dt = new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 31); + +dt = new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 30); + +dt = new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 31); + +dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 31); + +dt = new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 30); + +dt = new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 31); + +dt = new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13); +assert.sameValue(cal.daysInMonth(dt), 30); + +dt = new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13); +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 new file mode 100644 index 00000000000..32df3782424 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/plain-date.js @@ -0,0 +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: | + 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let d = new Temporal.PlainDate(2021, 1, 15); +assert.sameValue(cal.daysInMonth(d), 31); + +// non-leap year +d = new Temporal.PlainDate(2021, 2, 15); +assert.sameValue(cal.daysInMonth(d), 28); + +// leap year +d = new Temporal.PlainDate(2020, 2, 15); +assert.sameValue(cal.daysInMonth(d), 29); +d = new Temporal.PlainDate(2000, 2, 15); +assert.sameValue(cal.daysInMonth(d), 29); + +d = new Temporal.PlainDate(2021, 3, 15); +assert.sameValue(cal.daysInMonth(d), 31); + +d = new Temporal.PlainDate(2021, 4, 15); +assert.sameValue(cal.daysInMonth(d), 30); + +d = new Temporal.PlainDate(2021, 5, 15); +assert.sameValue(cal.daysInMonth(d), 31); + +d = new Temporal.PlainDate(2021, 6, 15); +assert.sameValue(cal.daysInMonth(d), 30); + +d = new Temporal.PlainDate(2021, 7, 15); +assert.sameValue(cal.daysInMonth(d), 31); + +d = new Temporal.PlainDate(2021, 8, 15); +assert.sameValue(cal.daysInMonth(d), 31); + +d = new Temporal.PlainDate(2021, 9, 15); +assert.sameValue(cal.daysInMonth(d), 30); + +d = new Temporal.PlainDate(2021, 10, 15); +assert.sameValue(cal.daysInMonth(d), 31); + +d = new Temporal.PlainDate(2021, 11, 15); +assert.sameValue(cal.daysInMonth(d), 30); + +d = new Temporal.PlainDate(2021, 12, 15); +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 new file mode 100644 index 00000000000..e3033dffc56 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/string.js @@ -0,0 +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.daysinmonth +description: Temporal.Calendar.prototype.daysInMonth will take ISO8601 string + and return the number of days in that month. +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). + 5. Return 𝔽(! ISODaysInMonth(temporalDateLike.[[ISOYear]], temporalDateLike.[[ISOMonth]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(cal.daysInMonth("2019-01-18"), 31); +// leap year +assert.sameValue(cal.daysInMonth("2020-02-18"), 29); +// non leap +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 new file mode 100644 index 00000000000..d2909b40f7d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date-time.js @@ -0,0 +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: | + 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"); + +let dt = new Temporal.PlainDateTime(1995, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(1996, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 366); + +dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(1998, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(1999, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(2000, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 366); + +dt = new Temporal.PlainDateTime(2001, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(2002, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(2003, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 365); + +dt = new Temporal.PlainDateTime(2004, 8, 23, 5, 30, 13); +assert.sameValue(cal.daysInYear(dt), 366); + +dt = new Temporal.PlainDateTime(2005, 8, 23, 5, 30, 13); +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 new file mode 100644 index 00000000000..7025f271c66 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/plain-date.js @@ -0,0 +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: | + 5. Return 𝔽(! ISODaysInYear(temporalDateLike.[[ISOYear]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let d = new Temporal.PlainDate(1995, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(1996, 7, 15); +assert.sameValue(cal.daysInYear(d), 366); + +d = new Temporal.PlainDate(1997, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(1998, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(1999, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(2000, 7, 15); +assert.sameValue(cal.daysInYear(d), 366); + +d = new Temporal.PlainDate(2001, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(2002, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(2003, 7, 15); +assert.sameValue(cal.daysInYear(d), 365); + +d = new Temporal.PlainDate(2004, 7, 15); +assert.sameValue(cal.daysInYear(d), 366); + +d = new Temporal.PlainDate(2005, 7, 15); +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 new file mode 100644 index 00000000000..f7dff2790b4 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/string.js @@ -0,0 +1,22 @@ +// 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: | + 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(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");