diff --git a/test/built-ins/Temporal/Calendar/prototype/day-of-week/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/day-of-week/plain-date-time.js new file mode 100644 index 0000000000..0b12240785 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day-of-week/plain-date-time.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.dayofweek +description: Temporal.Calendar.prototype.dayOfWeek will take Temporal.PlainDateTime objects + and return the day of week. + +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. Let temporalDate be ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13))); +// leap year +assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDateTime(1996, 2, 23, 5, 30, 13))); +assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDateTime(2000, 2, 23, 5, 30, 13))); +// non leap year +assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13))); +assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13))); +assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 4, 23, 5, 30, 13))); +assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 5, 23, 5, 30, 13))); +assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 6, 23, 5, 30, 13))); +assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 7, 23, 5, 30, 13))); +assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 8, 23, 5, 30, 13))); +assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 9, 23, 5, 30, 13))); +assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 10, 23, 5, 30, 13))); +assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 11, 23, 5, 30, 13))); +assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDateTime(1997, 12, 23, 5, 30, 13))); diff --git a/test/built-ins/Temporal/Calendar/prototype/day-of-week/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/day-of-week/plain-date.js new file mode 100644 index 0000000000..34f7da6d02 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day-of-week/plain-date.js @@ -0,0 +1,37 @@ +// 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.dayofweek +description: Temporal.Calendar.prototype.dayOfWeek will take Temporal.PlainDate objects + and return the day of week. + +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. Let temporalDate be ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDate(1970, 1, 1))); +assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDate(2000, 1, 1))); + +assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDate(2021, 1, 15))); +// leap year +assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDate(2020, 2, 15))); +assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDate(2000, 2, 15))); +// non-leap year +assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 2, 15))); +assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 3, 15))); +assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDate(2021, 4, 15))); +assert.sameValue(6, cal.dayOfWeek(new Temporal.PlainDate(2021, 5, 15))); +assert.sameValue(2, cal.dayOfWeek(new Temporal.PlainDate(2021, 6, 15))); +assert.sameValue(4, cal.dayOfWeek(new Temporal.PlainDate(2021, 7, 15))); +assert.sameValue(7, cal.dayOfWeek(new Temporal.PlainDate(2021, 8, 15))); +assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDate(2021, 9, 15))); +assert.sameValue(5, cal.dayOfWeek(new Temporal.PlainDate(2021, 10, 15))); +assert.sameValue(1, cal.dayOfWeek(new Temporal.PlainDate(2021, 11, 15))); +assert.sameValue(3, cal.dayOfWeek(new Temporal.PlainDate(2021, 12, 15))); diff --git a/test/built-ins/Temporal/Calendar/prototype/day-of-week/string.js b/test/built-ins/Temporal/Calendar/prototype/day-of-week/string.js new file mode 100644 index 0000000000..4b42a87f9a --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day-of-week/string.js @@ -0,0 +1,33 @@ +// 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.dayofweek +description: Temporal.Calendar.prototype.dayOfWeek will take ISO8601 string + and return the day of week. + +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. Let temporalDate be ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ToISODayOfWeek(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(5, cal.dayOfWeek("2019-01-18")); +// leap year +assert.sameValue(2, cal.dayOfWeek("2020-02-18")); +// non leap +assert.sameValue(1, cal.dayOfWeek("2019-02-18")); +assert.sameValue(1, cal.dayOfWeek("2019-03-18")); +assert.sameValue(4, cal.dayOfWeek("2019-04-18")); +assert.sameValue(6, cal.dayOfWeek("2019-05-18")); +assert.sameValue(2, cal.dayOfWeek("2019-06-18")); +assert.sameValue(4, cal.dayOfWeek("2019-07-18")); +assert.sameValue(7, cal.dayOfWeek("2019-08-18")); +assert.sameValue(3, cal.dayOfWeek("2019-09-18")); +assert.sameValue(5, cal.dayOfWeek("2019-10-18")); +assert.sameValue(1, cal.dayOfWeek("2019-11-18")); +assert.sameValue(3, cal.dayOfWeek("2019-12-18")); diff --git a/test/built-ins/Temporal/Calendar/prototype/day-of-year/plain-date-time.js b/test/built-ins/Temporal/Calendar/prototype/day-of-year/plain-date-time.js new file mode 100644 index 0000000000..f90e7ec44d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day-of-year/plain-date-time.js @@ -0,0 +1,24 @@ +// 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.dayofyear +description: Temporal.Calendar.prototype.dayOfYear will take PlainDateTime object and +return the day of year. + 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. Let temporalDate be ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(23, cal.dayOfYear(new Temporal.PlainDateTime(1997, 1, 23, 5, 30, 13))); +assert.sameValue(54, cal.dayOfYear(new Temporal.PlainDateTime(1997, 2, 23, 5, 30, 13))); +assert.sameValue(83, cal.dayOfYear(new Temporal.PlainDateTime(1996, 3, 23, 5, 30, 13))); +assert.sameValue(82, cal.dayOfYear(new Temporal.PlainDateTime(1997, 3, 23, 5, 30, 13))); +assert.sameValue(365, cal.dayOfYear(new Temporal.PlainDateTime(1997, 12, 31, 5, 30, 13))); +assert.sameValue(366, cal.dayOfYear(new Temporal.PlainDateTime(1996, 12, 31, 5, 30, 13))); diff --git a/test/built-ins/Temporal/Calendar/prototype/day-of-year/plain-date.js b/test/built-ins/Temporal/Calendar/prototype/day-of-year/plain-date.js new file mode 100644 index 0000000000..5e80fa49e8 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day-of-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.dayofyear +description: Temporal.Calendar.prototype.dayOfYear will take PlainDate object and +return the day of year. + 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. Let temporalDate be ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(1, cal.dayOfYear(new Temporal.PlainDate(1970, 1, 1))); +assert.sameValue(1, cal.dayOfYear(new Temporal.PlainDate(2000, 1, 1))); + +assert.sameValue(15, cal.dayOfYear(new Temporal.PlainDate(2021, 1, 15))); +assert.sameValue(46, cal.dayOfYear(new Temporal.PlainDate(2020, 2, 15))); +assert.sameValue(46, cal.dayOfYear(new Temporal.PlainDate(2000, 2, 15))); +assert.sameValue(75, cal.dayOfYear(new Temporal.PlainDate(2020, 3, 15))); +assert.sameValue(75, cal.dayOfYear(new Temporal.PlainDate(2000, 3, 15))); +assert.sameValue(74, cal.dayOfYear(new Temporal.PlainDate(2001, 3, 15))); +assert.sameValue(366, cal.dayOfYear(new Temporal.PlainDate(2000, 12, 31))); +assert.sameValue(365, cal.dayOfYear(new Temporal.PlainDate(2001, 12, 31))); diff --git a/test/built-ins/Temporal/Calendar/prototype/day-of-year/string.js b/test/built-ins/Temporal/Calendar/prototype/day-of-year/string.js new file mode 100644 index 0000000000..9c39583bd2 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day-of-year/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.dayofyear +description: Temporal.Calendar.prototype.dayOfYear will take ISO8601 string and +return the day of year. + 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. Let temporalDate be ? ToTemporalDate(temporalDateLike). + 5. Return 𝔽(! ToISODayOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601"); + +assert.sameValue(18, cal.dayOfYear("2019-01-18")); +assert.sameValue(49, cal.dayOfYear("2020-02-18")); +assert.sameValue(365, cal.dayOfYear("2019-12-31")); +assert.sameValue(366, cal.dayOfYear("2000-12-31"));