diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js new file mode 100644 index 00000000000..e45fd322426 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date-time.js @@ -0,0 +1,18 @@ +// 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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDateTime + object and return the number 12 for ISO8601 calendar. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let dt = new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13); +assert.sameValue(cal.monthsInYear(dt), 12); +dt = new Temporal.PlainDateTime(1221, 8, 23, 5, 30, 13); +assert.sameValue(cal.monthsInYear(dt), 12); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js new file mode 100644 index 00000000000..af4a0988fec --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js @@ -0,0 +1,18 @@ +// 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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear will take Temporal.PlainDate + and return the number 12 for ISO8601 calendar. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let d = new Temporal.PlainDate(2021, 7, 15); +assert.sameValue(12, cal.monthsInYear(d), 12); +d = new Temporal.PlainDate(1234, 12, 3); +assert.sameValue(12, cal.monthsInYear(d), 12); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.js new file mode 100644 index 00000000000..8aaa2702a8e --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string-throw-range-error.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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear will throw RangeError with incorrect ISO8601 string. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.throws(RangeError, () => cal.monthsInYear("2021-01"), "Missing day"); +assert.throws(RangeError, () => cal.monthsInYear("2019-12"), "Missing day"); +assert.throws(RangeError, () => cal.monthsInYear("P1Y"), "Duration is not acceptable"); +assert.throws(RangeError, () => cal.monthsInYear("-P12Y"), "Duration is not acceptable"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.js new file mode 100644 index 00000000000..e4d5e9570e5 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/string.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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear will take ISO8601 string + and return the number 12 for ISO8601 calendar. +info: | + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(cal.monthsInYear("3456-12-20"), 12); +assert.sameValue(cal.monthsInYear("+000998-01-28"), 12); +assert.sameValue(cal.monthsInYear("3456-12-20T03:04:05Z"), 12); +assert.sameValue(cal.monthsInYear("+000998-01-28T03:04:05Z"), 12); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-range-error-ToTemporalDate.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-range-error-ToTemporalDate.js new file mode 100644 index 00000000000..cdad67fc7bc --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear 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.monthsInYear("invalid string"), + "Throw RangeError if temporalDateLike is invalid"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-type-error-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/throw-type-error-RequireInternalSlot.js new file mode 100644 index 00000000000..ac3ce1e5f92 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear 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 = { monthsInYear: cal.monthsInYear } +assert.throws(TypeError, () => badCal.monthsInYear("2021-03-04"), + "Throw TypeError if there are no internal slot"); diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js new file mode 100644 index 00000000000..884e5e4b811 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/year-month.js @@ -0,0 +1,18 @@ +// 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.monthsinyear +description: Temporal.Calendar.prototype.monthsInYear will take + PlainYearMonth object and return the number 12 for ISO8601 calendar. +info: | + 4. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]] or [[InitializedTemporalYearMonth]] internal slot, then + a. Perform ? ToTemporalDate(temporalDateLike). + 5. Return 12𝔽. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +let ym = new Temporal.PlainYearMonth(1, 1); +assert.sameValue(cal.monthsInYear(ym), 12); +ym = new Temporal.PlainYearMonth(9384, 3); +assert.sameValue(cal.monthsInYear(ym), 12);