From 78f5075d5b4e7c2eb2ecafef0d4013b0a7896ab2 Mon Sep 17 00:00:00 2001 From: Aditi Date: Thu, 15 Feb 2024 23:26:13 +0530 Subject: [PATCH 1/2] Temporal: Tests for week-numbering algorithm --- .../weekOfYear/validate-calendar-value.js | 1 - .../yearOfWeek/validate-calendar-value.js | 1 - .../weekOfYear/validate-calendar-value.js | 1 - .../yearOfWeek/validate-calendar-value.js | 1 - .../weekOfYear/validate-calendar-value.js | 1 - .../yearOfWeek/validate-calendar-value.js | 1 - .../weekOfYear/non-iso-week-of-year.js | 22 +++++++++++++++++ .../yearOfWeek/non-iso-week-of-year.js | 22 +++++++++++++++++ .../weekOfYear/non-iso-week-of-year.js | 22 +++++++++++++++++ .../yearOfWeek/non-iso-week-of-year.js | 22 +++++++++++++++++ .../weekOfYear/non-iso-week-of-year.js | 22 +++++++++++++++++ .../yearOfWeek/non-iso-week-of-year.js | 22 +++++++++++++++++ .../weekOfYear/non-iso-week-of-year.js | 24 +++++++++++++++++++ .../yearOfWeek/non-iso-week-of-year.js | 24 +++++++++++++++++++ 14 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 test/intl402/Temporal/Calendar/prototype/weekOfYear/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/Calendar/prototype/yearOfWeek/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/weekOfYear/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/yearOfWeek/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/non-iso-week-of-year.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/non-iso-week-of-year.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js index f8bcc7ecce9..0033b10161e 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js +++ b/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js @@ -8,7 +8,6 @@ features: [Temporal] ---*/ const badResults = [ - [undefined, TypeError], [null, TypeError], [false, TypeError], [Infinity, RangeError], diff --git a/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/validate-calendar-value.js index 5a44767f6b5..e8f682dad2f 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/validate-calendar-value.js +++ b/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/validate-calendar-value.js @@ -8,7 +8,6 @@ features: [Temporal] ---*/ const badResults = [ - [undefined, TypeError], [Infinity, RangeError], [-Infinity, RangeError], [Symbol("foo"), TypeError], diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js index e8aeb1d742e..69ff6a2c5ce 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js @@ -8,7 +8,6 @@ features: [Temporal] ---*/ const badResults = [ - [undefined, TypeError], [null, TypeError], [false, TypeError], [Infinity, RangeError], diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js index d80ce15fa1c..0efa0075acb 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/validate-calendar-value.js @@ -8,7 +8,6 @@ features: [Temporal] ---*/ const badResults = [ - [undefined, TypeError], [Infinity, RangeError], [-Infinity, RangeError], [Symbol("foo"), TypeError], diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js index 9d6f448656e..fe3ba667d7c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js @@ -8,7 +8,6 @@ features: [Temporal] ---*/ const badResults = [ - [undefined, TypeError], [null, TypeError], [false, TypeError], [Infinity, RangeError], diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/validate-calendar-value.js index 64a027b2dd7..6b87e8a8b25 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/validate-calendar-value.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/validate-calendar-value.js @@ -8,7 +8,6 @@ features: [Temporal] ---*/ const badResults = [ - [undefined, TypeError], [Infinity, RangeError], [-Infinity, RangeError], [Symbol("foo"), TypeError], diff --git a/test/intl402/Temporal/Calendar/prototype/weekOfYear/non-iso-week-of-year.js b/test/intl402/Temporal/Calendar/prototype/weekOfYear/non-iso-week-of-year.js new file mode 100644 index 00000000000..f36305b29a2 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/weekOfYear/non-iso-week-of-year.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. 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 returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); +const date = { month: 1, day: 1, year: 2024, calendar}; + +assert.sameValue(calendar.weekOfYear({...date}), 1); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = { month: 1, day: 1, year: 2024, calendar}; + +assert.sameValue(calendar.weekOfYear({...nonisodate}), undefined); diff --git a/test/intl402/Temporal/Calendar/prototype/yearOfWeek/non-iso-week-of-year.js b/test/intl402/Temporal/Calendar/prototype/yearOfWeek/non-iso-week-of-year.js new file mode 100644 index 00000000000..4337ed0918e --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/yearOfWeek/non-iso-week-of-year.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearofweek +description: > + Temporal.Calendar.prototype.yearOfWeek returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); +const date = { month: 1, day: 1, year: 2024, calendar}; + +assert.sameValue(calendar.yearOfWeek({...date}), 2024); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = { month: 1, day: 1, year: 2024, calendar}; + +assert.sameValue(calendar.yearOfWeek({...nonisodate}), undefined); diff --git a/test/intl402/Temporal/PlainDate/prototype/weekOfYear/non-iso-week-of-year.js b/test/intl402/Temporal/PlainDate/prototype/weekOfYear/non-iso-week-of-year.js new file mode 100644 index 00000000000..86c46b497d7 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/weekOfYear/non-iso-week-of-year.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.weekofyear +description: > + Temporal.PlainDate.prototype.weekOfYear returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDate(2024, 1, 1, calendar); + +assert.sameValue(date.weekOfYear, 1); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = new Temporal.PlainDate(2024, 1, 1, calendar); + +assert.sameValue(nonisodate.weekOfYear, undefined); diff --git a/test/intl402/Temporal/PlainDate/prototype/yearOfWeek/non-iso-week-of-year.js b/test/intl402/Temporal/PlainDate/prototype/yearOfWeek/non-iso-week-of-year.js new file mode 100644 index 00000000000..e378c0884c4 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/yearOfWeek/non-iso-week-of-year.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.yearofweek +description: > + Temporal.PlainDate.prototype.yearOfWeek returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDate(2024, 1, 1, calendar); + +assert.sameValue(date.yearOfWeek, 2024); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = new Temporal.PlainDate(2024, 1, 1, calendar); + +assert.sameValue(nonisodate.yearOfWeek, undefined); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/non-iso-week-of-year.js b/test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/non-iso-week-of-year.js new file mode 100644 index 00000000000..1eb4e566bb6 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/non-iso-week-of-year.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.weekofyear +description: > + Temporal.PlainDateTime.prototype.weekOfYear returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(date.weekOfYear, 1); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(nonisodate.weekOfYear, undefined); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/non-iso-week-of-year.js b/test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/non-iso-week-of-year.js new file mode 100644 index 00000000000..35c1b13f18d --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/non-iso-week-of-year.js @@ -0,0 +1,22 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.yearofweek +description: > + Temporal.PlainDateTime.prototype.yearOfWeek returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(date.yearOfWeek, 2024); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(nonisodate.yearOfWeek, undefined); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/non-iso-week-of-year.js b/test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/non-iso-week-of-year.js new file mode 100644 index 00000000000..c5f23944169 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/non-iso-week-of-year.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.weekofyear +description: > + Temporal.ZonedDateTime.prototype.weekOfYear returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); + +// Epoch Nanoseconds for new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); +const date = new Temporal.ZonedDateTime(1_704_112_496_987_654_321n, "UTC", calendar); + +assert.sameValue(date.weekOfYear, 1); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = new Temporal.ZonedDateTime(1_704_112_496_987_654_321n, "UTC", calendar); + +assert.sameValue(nonisodate.weekOfYear, undefined); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/non-iso-week-of-year.js b/test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/non-iso-week-of-year.js new file mode 100644 index 00000000000..7e163fa529d --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/non-iso-week-of-year.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.yearofweek +description: > + Temporal.ZonedDateTime.prototype.yearOfWeek returns undefined for all + non-ISO calendars without a well-defined week numbering system. +features: [Temporal] +---*/ + +// Gregorian calendar has a well defined week-numbering system. + +let calendar = new Temporal.Calendar("gregory"); + +// Epoch Nanoseconds for new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); +const date = new Temporal.ZonedDateTime(1_704_112_496_987_654_321n, "UTC", calendar); + +assert.sameValue(date.yearOfWeek, 2024); + +calendar = new Temporal.Calendar("hebrew"); +const nonisodate = new Temporal.ZonedDateTime(1_704_112_496_987_654_321n, "UTC", calendar); + +assert.sameValue(nonisodate.yearOfWeek, undefined); From c5f991d03b813167df4b4163d5d52c70bc142e91 Mon Sep 17 00:00:00 2001 From: Aditi Date: Wed, 21 Feb 2024 19:31:27 +0530 Subject: [PATCH 2/2] Temporal: Add weekOfYear() and yearOfWeek() tests for custom calendars --- .../weekOfYear/custom-calendar-weekofyear.js | 23 ++++++++++++++++ .../yearOfWeek/custom-calendar-weekofyear.js | 23 ++++++++++++++++ .../weekOfYear/custom-calendar-weekofyear.js | 23 ++++++++++++++++ .../yearOfWeek/custom-calendar-weekofyear.js | 23 ++++++++++++++++ .../weekOfYear/custom-calendar-weekofyear.js | 23 ++++++++++++++++ .../yearOfWeek/custom-calendar-weekofyear.js | 23 ++++++++++++++++ .../weekOfYear/custom-calendar-weekofyear.js | 24 +++++++++++++++++ .../yearOfWeek/custom-calendar-weekofyear.js | 24 +++++++++++++++++ .../weekOfYear/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../yearOfWeek/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../weekOfYear/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../yearOfWeek/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../weekOfYear/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../yearOfWeek/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../weekOfYear/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ .../yearOfWeek/gregory-iso-weekofyear.js | 27 +++++++++++++++++++ 16 files changed, 402 insertions(+) create mode 100644 test/built-ins/Temporal/Calendar/prototype/weekOfYear/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/yearOfWeek/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/weekOfYear/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js create mode 100644 test/intl402/Temporal/Calendar/prototype/weekOfYear/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/Calendar/prototype/yearOfWeek/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/weekOfYear/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/yearOfWeek/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/custom-calendar-weekofyear.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..c9871143617 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/custom-calendar-weekofyear.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. 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 returns undefined for all + custom calendars where weekOfYear() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + weekOfYear() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +const customCalendarDate = { month: 1, day: 1, year: 2024, calendar}; +assert.sameValue(calendar.weekOfYear({...customCalendarDate}), undefined); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/custom-calendar-weekofyear.js b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..0440497eb9b --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/custom-calendar-weekofyear.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearofweek +description: > + Temporal.Calendar.prototype.yearOfWeek returns undefined for all + custom calendars where yearOfWeek() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + yearOfWeek() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +const customCalendarDate = { month: 1, day: 1, year: 2024, calendar}; +assert.sameValue(calendar.yearOfWeek({...customCalendarDate}), undefined); diff --git a/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/custom-calendar-weekofyear.js b/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..35261207ed9 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/custom-calendar-weekofyear.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.weekofyear +description: > + Temporal.PlainDate.prototype.weekOfYear returns undefined for all + custom calendars where weekOfYear() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + weekOfYear() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +const customCalendarDate = new Temporal.PlainDate(2024, 1, 1, calendar); +assert.sameValue(customCalendarDate.weekOfYear, undefined); diff --git a/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/custom-calendar-weekofyear.js b/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..fdb51a1b172 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/yearOfWeek/custom-calendar-weekofyear.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.yearofweek +description: > + Temporal.PlainDate.prototype.yearOfWeek returns undefined for all + custom calendars where yearOfWeek() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + yearOfWeek() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +const customCalendarDate = new Temporal.PlainDate(2024, 1, 1, calendar); +assert.sameValue(customCalendarDate.yearOfWeek, undefined); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js b/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..f9b43f88afe --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.weekofyear +description: > + Temporal.PlainDateTime.prototype.weekOfYear returns undefined for all + custom calendars where weekOfYear() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + weekOfYear() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +const customCalendarDate = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); +assert.sameValue(customCalendarDate.weekOfYear, undefined); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js b/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..425b3a0360b --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js @@ -0,0 +1,23 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.yearofweek +description: > + Temporal.PlainDateTime.prototype.yearOfWeek returns undefined for all + custom calendars where yearOfWeek() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + yearOfWeek() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +const customCalendarDate = new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); +assert.sameValue(customCalendarDate.yearOfWeek, undefined); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js b/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..ed8df20d109 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/custom-calendar-weekofyear.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.weekofyear +description: > + Temporal.ZonedDateTime.prototype.weekOfYear returns undefined for all + custom calendars where weekOfYear() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + weekOfYear() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +// Epoch Nanoseconds for new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); +const customCalendarDate = new Temporal.ZonedDateTime(1_704_112_496_987_654_321n, "UTC", calendar); +assert.sameValue(customCalendarDate.weekOfYear, undefined); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js b/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js new file mode 100644 index 00000000000..0c5c3723c79 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/yearOfWeek/custom-calendar-weekofyear.js @@ -0,0 +1,24 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.yearofweek +description: > + Temporal.ZonedDateTime.prototype.yearOfWeek returns undefined for all + custom calendars where yearOfWeek() returns undefined. +features: [Temporal] +---*/ + +class CustomCalendar extends Temporal.Calendar { + constructor() { + super("iso8601"); + } + yearOfWeek() { + return undefined; + } +} + +const calendar = new CustomCalendar(); +// Epoch Nanoseconds for new Temporal.PlainDateTime(2024, 1, 1, 12, 34, 56, 987, 654, 321, calendar); +const customCalendarDate = new Temporal.ZonedDateTime(1_704_112_496_987_654_321n, "UTC", calendar); +assert.sameValue(customCalendarDate.yearOfWeek, undefined); diff --git a/test/intl402/Temporal/Calendar/prototype/weekOfYear/gregory-iso-weekofyear.js b/test/intl402/Temporal/Calendar/prototype/weekOfYear/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..1b2d2d3d4b9 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/weekOfYear/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.weekofyear +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = { month: 1, day: 1, year: 2021, calendar}; + +assert.sameValue(calendar.weekOfYear({...date}), 1); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = { month: 1, day: 1, year: 2021, calendar}; + +assert.sameValue(calendar.weekOfYear({...isodate}), 53); diff --git a/test/intl402/Temporal/Calendar/prototype/yearOfWeek/gregory-iso-weekofyear.js b/test/intl402/Temporal/Calendar/prototype/yearOfWeek/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..65f73d7a2bc --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/yearOfWeek/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearofweek +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = { month: 1, day: 1, year: 2021, calendar}; + +assert.sameValue(calendar.yearOfWeek({...date}), 2021); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = { month: 1, day: 1, year: 2021, calendar}; + +assert.sameValue(calendar.yearOfWeek({...isodate}), 2020); diff --git a/test/intl402/Temporal/PlainDate/prototype/weekOfYear/gregory-iso-weekofyear.js b/test/intl402/Temporal/PlainDate/prototype/weekOfYear/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..4d023823352 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/weekOfYear/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.weekofyear +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDate(2021, 1, 1, calendar); + +assert.sameValue(date.weekOfYear, 1); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = new Temporal.PlainDate(2021, 1, 1, calendar); + +assert.sameValue(isodate.weekOfYear, 53); diff --git a/test/intl402/Temporal/PlainDate/prototype/yearOfWeek/gregory-iso-weekofyear.js b/test/intl402/Temporal/PlainDate/prototype/yearOfWeek/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..70252942e90 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/yearOfWeek/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.yearofweek +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDate(2021, 1, 1, calendar); + +assert.sameValue(date.yearOfWeek, 2021); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = new Temporal.PlainDate(2021, 1, 1, calendar); + +assert.sameValue(isodate.yearOfWeek, 2020); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js b/test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..6f79fd1c117 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.weekofyear +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDateTime(2021, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(date.weekOfYear, 1); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = new Temporal.PlainDateTime(2021, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(isodate.weekOfYear, 53); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js b/test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..63bd715a1b2 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.yearofweek +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.PlainDateTime(2021, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(date.yearOfWeek, 2021); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = new Temporal.PlainDateTime(2021, 1, 1, 12, 34, 56, 987, 654, 321, calendar); + +assert.sameValue(isodate.yearOfWeek, 2020); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js b/test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..c02e49a0b4d --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/weekOfYear/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.weekofyear +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.ZonedDateTime(1_609_504_496_987_654_321n, "UTC", calendar); + +assert.sameValue(date.weekOfYear, 1); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = new Temporal.ZonedDateTime(1_609_504_496_987_654_321n, "UTC", calendar); + +assert.sameValue(isodate.weekOfYear, 53); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js b/test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js new file mode 100644 index 00000000000..439a5173d11 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/yearOfWeek/gregory-iso-weekofyear.js @@ -0,0 +1,27 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.yearofweek +description: > + In the ISO 8601 week calendar, calendar week number 1 of a calendar year is + the week including the first Thursday of that year (based on the principle + that a week belongs to the same calendar year as the majority of its calendar + days). Because of this, some calendar days of the first calendar week of a + calendar year may be part of the preceding date calendar year, and some + calendar days of the last calendar week of a calendar year may be part of + the next calendar year. +features: [Temporal] +---*/ + +// + +let calendar = new Temporal.Calendar("gregory"); +const date = new Temporal.ZonedDateTime(1_609_504_496_987_654_321n, "UTC", calendar); + +assert.sameValue(date.yearOfWeek, 2021); + +calendar = new Temporal.Calendar("iso8601"); +const isodate = new Temporal.ZonedDateTime(1_609_504_496_987_654_321n, "UTC", calendar); + +assert.sameValue(isodate.yearOfWeek, 2020);