Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Temporal.Calendar.p*.monthsInYear #3059

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
18 changes: 18 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/monthsInYear/date.js
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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);