forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Temporal.Calendar.p*.weekOfYear
(Philip, March 2022: This was originally Frank's PR tc39#3060. I did some reformatting, removed a test that didn't exercise the whole feature, and combined some duplicate tests with some existing tests.)
- Loading branch information
1 parent
ac19506
commit b064eb6
Showing
4 changed files
with
202 additions
and
9 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-plaindate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 76 additions & 0 deletions
76
test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-plaindatetime.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
39 changes: 39 additions & 0 deletions
39
test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters