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 Temporal.Calendar.prototype.daysIn* tests. #3052

Merged
merged 6 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,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)));
Original file line number Diff line number Diff line change
@@ -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)));
34 changes: 34 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/days-in-month/string.js
Original file line number Diff line number Diff line change
@@ -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"));
20 changes: 20 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/days-in-week/simple.js
Original file line number Diff line number Diff line change
@@ -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"));
Original file line number Diff line number Diff line change
@@ -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)));
Original file line number Diff line number Diff line change
@@ -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)));
50 changes: 50 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/days-in-year/string.js
Original file line number Diff line number Diff line change
@@ -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"));