mirror of https://github.com/tc39/test262.git
Add tests for Temporal.Calendar.p*.weekOfYear
(Philip, March 2022: This was originally Frank's PR #3060. I did some reformatting, removed a test that didn't exercise the whole feature, and combined some duplicate tests with some existing tests.)
This commit is contained in:
parent
ac19506a01
commit
b064eb64f3
|
@ -0,0 +1,76 @@
|
|||
// 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.weekofyear
|
||||
description: >
|
||||
Temporal.Calendar.prototype.weekOfYear will take Temporal.PlainDate object
|
||||
and return the week of year of that date.
|
||||
info: |
|
||||
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
|
||||
5. Return 𝔽(! ToISOWeekOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const cal = new Temporal.Calendar("iso8601");
|
||||
|
||||
// The following week numbers are taken from the table "Examples of contemporary
|
||||
// dates around New Year's Day" from
|
||||
// https://en.wikipedia.org/wiki/ISO_week_date#Relation_with_the_Gregorian_calendar
|
||||
|
||||
let d = new Temporal.PlainDate(1977, 1, 1);
|
||||
assert.sameValue(cal.weekOfYear(d), 53, "1977-01-01 is in w53");
|
||||
|
||||
d = new Temporal.PlainDate(1977, 1, 2);
|
||||
assert.sameValue(cal.weekOfYear(d), 53, "1977-01-02 is in w53");
|
||||
|
||||
d = new Temporal.PlainDate(1977, 12, 31);
|
||||
assert.sameValue(cal.weekOfYear(d), 52, "1977-12-31 is in w52");
|
||||
|
||||
d = new Temporal.PlainDate(1978, 1, 1);
|
||||
assert.sameValue(cal.weekOfYear(d), 52, "1978-01-01 is in w52");
|
||||
|
||||
d = new Temporal.PlainDate(1978, 1, 2);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1978-01-02 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1978, 12, 31);
|
||||
assert.sameValue(cal.weekOfYear(d), 52, "1978-12-31 is in w52");
|
||||
|
||||
d = new Temporal.PlainDate(1979, 1, 1);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1979-01-01 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1979, 12, 30);
|
||||
assert.sameValue(cal.weekOfYear(d), 52, "1979-12-30 is in w52");
|
||||
|
||||
d = new Temporal.PlainDate(1979, 12, 31);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1979-12-31 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1980, 1, 1);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1980-01-01 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1980, 12, 28);
|
||||
assert.sameValue(cal.weekOfYear(d), 52, "1980-12-28 is in w52");
|
||||
|
||||
d = new Temporal.PlainDate(1980, 12, 29);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1980-12-29 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1980, 12, 30);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1980-12-30 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1980, 12, 31);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1980-12-31 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1981, 1, 1);
|
||||
assert.sameValue(cal.weekOfYear(d), 1, "1981-01-01 is in w01");
|
||||
|
||||
d = new Temporal.PlainDate(1981, 12, 31);
|
||||
assert.sameValue(cal.weekOfYear(d), 53, "1981-12-31 is in w53");
|
||||
|
||||
d = new Temporal.PlainDate(1982, 1, 1);
|
||||
assert.sameValue(cal.weekOfYear(d), 53, "1982-01-01 is in w53");
|
||||
|
||||
d = new Temporal.PlainDate(1982, 1, 2);
|
||||
assert.sameValue(cal.weekOfYear(d), 53, "1982-01-02 is in w53");
|
||||
|
||||
d = new Temporal.PlainDate(1982, 1, 3);
|
||||
assert.sameValue(cal.weekOfYear(d), 53, "1982-01-03 is in w53");
|
76
test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-plaindatetime.js
vendored
Normal file
76
test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-plaindatetime.js
vendored
Normal file
|
@ -0,0 +1,76 @@
|
|||
// 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.weekofyear
|
||||
description: >
|
||||
Temporal.Calendar.prototype.weekOfYear will take Temporal.PlainDateTime object
|
||||
and return the week of year of that date.
|
||||
info: |
|
||||
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
|
||||
5. Return 𝔽(! ToISOWeekOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const cal = new Temporal.Calendar("iso8601");
|
||||
|
||||
// The following week numbers are taken from the table "Examples of contemporary
|
||||
// dates around New Year's Day" from
|
||||
// https://en.wikipedia.org/wiki/ISO_week_date#Relation_with_the_Gregorian_calendar
|
||||
|
||||
let dt = new Temporal.PlainDateTime(1977, 1, 1, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 53, "1977-01-01 is in w53");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1977, 1, 2, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 53, "1977-01-02 is in w53");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1977, 12, 31, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 52, "1977-12-31 is in w52");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1978, 1, 1, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 52, "1978-01-01 is in w52");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1978, 1, 2, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1978-01-02 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1978, 12, 31, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 52, "1978-12-31 is in w52");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1979, 1, 1, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1979-01-01 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1979, 12, 30, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 52, "1979-12-30 is in w52");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1979, 12, 31, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1979-12-31 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1980, 1, 1, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1980-01-01 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1980, 12, 28, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 52, "1980-12-28 is in w52");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1980, 12, 29, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1980-12-29 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1980, 12, 30, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1980-12-30 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1980, 12, 31, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1980-12-31 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1981, 1, 1, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 1, "1981-01-01 is in w01");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1981, 12, 31, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 53, "1981-12-31 is in w53");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1982, 1, 1, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 53, "1982-01-01 is in w53");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1982, 1, 2, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 53, "1982-01-02 is in w53");
|
||||
|
||||
dt = new Temporal.PlainDateTime(1982, 1, 3, 9, 8);
|
||||
assert.sameValue(cal.weekOfYear(dt), 53, "1982-01-03 is in w53");
|
|
@ -0,0 +1,39 @@
|
|||
// 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.weekofyear
|
||||
description: >
|
||||
Temporal.Calendar.prototype.weekOfYear will take an ISO 8601 date string and
|
||||
return the week of year of that date.
|
||||
info: |
|
||||
4. Let temporalDate be ? ToTemporalDate(temporalDateLike).
|
||||
5. Return 𝔽(! ToISOWeekOfYear(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]])).
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const cal = new Temporal.Calendar("iso8601");
|
||||
|
||||
// The following week numbers are taken from the table "Examples of contemporary
|
||||
// dates around New Year's Day" from
|
||||
// https://en.wikipedia.org/wiki/ISO_week_date#Relation_with_the_Gregorian_calendar
|
||||
|
||||
assert.sameValue(cal.weekOfYear("1977-01-01"), 53, "1977-01-01 is in w53");
|
||||
assert.sameValue(cal.weekOfYear("1977-01-02"), 53, "1977-01-02 is in w53");
|
||||
assert.sameValue(cal.weekOfYear("1977-12-31"), 52, "1977-12-31 is in w52");
|
||||
assert.sameValue(cal.weekOfYear("1978-01-01"), 52, "1978-01-01 is in w52");
|
||||
assert.sameValue(cal.weekOfYear("1978-01-02"), 1, "1978-01-02 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1978-12-31"), 52, "1978-12-31 is in w52");
|
||||
assert.sameValue(cal.weekOfYear("1979-01-01"), 1, "1979-01-01 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1979-12-30"), 52, "1979-12-30 is in w52");
|
||||
assert.sameValue(cal.weekOfYear("1979-12-31"), 1, "1979-12-31 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1980-01-01"), 1, "1980-01-01 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1980-12-28"), 52, "1980-12-28 is in w52");
|
||||
assert.sameValue(cal.weekOfYear("1980-12-29"), 1, "1980-12-29 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1980-12-30"), 1, "1980-12-30 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1980-12-31"), 1, "1980-12-31 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1981-01-01"), 1, "1981-01-01 is in w01");
|
||||
assert.sameValue(cal.weekOfYear("1981-12-31"), 53, "1981-12-31 is in w53");
|
||||
assert.sameValue(cal.weekOfYear("1982-01-01"), 53, "1982-01-01 is in w53");
|
||||
assert.sameValue(cal.weekOfYear("1982-01-02"), 53, "1982-01-02 is in w53");
|
||||
assert.sameValue(cal.weekOfYear("1982-01-03"), 53, "1982-01-03 is in w53");
|
|
@ -11,12 +11,14 @@ const weekOfYear = Temporal.Calendar.prototype.weekOfYear;
|
|||
|
||||
assert.sameValue(typeof weekOfYear, "function");
|
||||
|
||||
assert.throws(TypeError, () => weekOfYear.call(undefined), "undefined");
|
||||
assert.throws(TypeError, () => weekOfYear.call(null), "null");
|
||||
assert.throws(TypeError, () => weekOfYear.call(true), "true");
|
||||
assert.throws(TypeError, () => weekOfYear.call(""), "empty string");
|
||||
assert.throws(TypeError, () => weekOfYear.call(Symbol()), "symbol");
|
||||
assert.throws(TypeError, () => weekOfYear.call(1), "1");
|
||||
assert.throws(TypeError, () => weekOfYear.call({}), "plain object");
|
||||
assert.throws(TypeError, () => weekOfYear.call(Temporal.Calendar), "Temporal.Calendar");
|
||||
assert.throws(TypeError, () => weekOfYear.call(Temporal.Calendar.prototype), "Temporal.Calendar.prototype");
|
||||
const arg = new Temporal.PlainDate(2021, 7, 20);
|
||||
|
||||
assert.throws(TypeError, () => weekOfYear.call(undefined, arg), "undefined");
|
||||
assert.throws(TypeError, () => weekOfYear.call(null, arg), "null");
|
||||
assert.throws(TypeError, () => weekOfYear.call(true, arg), "true");
|
||||
assert.throws(TypeError, () => weekOfYear.call("", arg), "empty string");
|
||||
assert.throws(TypeError, () => weekOfYear.call(Symbol(), arg), "symbol");
|
||||
assert.throws(TypeError, () => weekOfYear.call(1, arg), "1");
|
||||
assert.throws(TypeError, () => weekOfYear.call({}, arg), "plain object");
|
||||
assert.throws(TypeError, () => weekOfYear.call(Temporal.Calendar, arg), "Temporal.Calendar");
|
||||
assert.throws(TypeError, () => weekOfYear.call(Temporal.Calendar.prototype, arg), "Temporal.Calendar.prototype");
|
||||
|
|
Loading…
Reference in New Issue