-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add getISOCalendarFields() method to calendar-dependent types
This is in order to be able to get the underlying fields from the data model, which are stored in the ISO 8601 calendar. It's not expected to be used in normal Temporal usage, it really exists only for calendar implementors. Closes: #354
- Loading branch information
Showing
29 changed files
with
568 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
16 changes: 16 additions & 0 deletions
16
polyfill/test/Date/prototype/getISOCalendarFields/branding.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,16 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
const getISOCalendarFields = Temporal.Date.prototype.getISOCalendarFields; | ||
|
||
assert.sameValue(typeof getISOCalendarFields, "function"); | ||
|
||
assert.throws(TypeError, () => getISOCalendarFields.call(undefined), "undefined"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(null), "null"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(true), "true"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(""), "empty string"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(Symbol()), "symbol"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(1), "1"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call({}), "plain object"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(Temporal.Date), "Temporal.Date"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(Temporal.Date.prototype), "Temporal.Date.prototype"); |
18 changes: 18 additions & 0 deletions
18
polyfill/test/Date/prototype/getISOCalendarFields/prop-desc.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,18 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue( | ||
typeof Temporal.Date.prototype.getISOCalendarFields, | ||
"function", | ||
"`typeof Date.prototype.getISOCalendarFields` is `function`" | ||
); | ||
|
||
verifyProperty(Temporal.Date.prototype, "getISOCalendarFields", { | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
}); |
31 changes: 31 additions & 0 deletions
31
polyfill/test/Date/prototype/getISOCalendarFields/subclass.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,31 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.date.prototype.getisocalendarfields | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
let called = 0; | ||
|
||
const constructorArguments = [ | ||
[2000, 5, 2] | ||
]; | ||
|
||
class MyDate extends Temporal.Date { | ||
constructor(year, month, day) { | ||
assert.compareArray([year, month, day], constructorArguments.shift(), "constructor arguments"); | ||
++called; | ||
super(year, month, day); | ||
} | ||
} | ||
|
||
const instance = MyDate.from("2000-05-02"); | ||
assert.sameValue(called, 1); | ||
|
||
const result = instance.getISOCalendarFields(); | ||
assert.sameValue(result.year, 2000, "year result"); | ||
assert.sameValue(result.month, 5, "month result"); | ||
assert.sameValue(result.day, 2, "day result"); | ||
assert.sameValue(called, 1); | ||
assert.sameValue(Object.getPrototypeOf(result), Object.prototype); |
16 changes: 16 additions & 0 deletions
16
polyfill/test/DateTime/prototype/getISOCalendarFields/branding.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,16 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
const getISOCalendarFields = Temporal.DateTime.prototype.getISOCalendarFields; | ||
|
||
assert.sameValue(typeof getISOCalendarFields, "function"); | ||
|
||
assert.throws(TypeError, () => getISOCalendarFields.call(undefined), "undefined"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(null), "null"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(true), "true"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(""), "empty string"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(Symbol()), "symbol"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(1), "1"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call({}), "plain object"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(Temporal.DateTime), "Temporal.DateTime"); | ||
assert.throws(TypeError, () => getISOCalendarFields.call(Temporal.DateTime.prototype), "Temporal.DateTime.prototype"); |
18 changes: 18 additions & 0 deletions
18
polyfill/test/DateTime/prototype/getISOCalendarFields/prop-desc.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,18 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue( | ||
typeof Temporal.DateTime.prototype.getISOCalendarFields, | ||
"function", | ||
"`typeof DateTime.prototype.getISOCalendarFields` is `function`" | ||
); | ||
|
||
verifyProperty(Temporal.DateTime.prototype, "getISOCalendarFields", { | ||
writable: true, | ||
enumerable: false, | ||
configurable: true, | ||
}); |
37 changes: 37 additions & 0 deletions
37
polyfill/test/DateTime/prototype/getISOCalendarFields/subclass.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,37 @@ | ||
// Copyright (C) 2020 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.datetime.prototype.getisocalendarfields | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
let called = 0; | ||
|
||
const constructorArguments = [ | ||
[2000, 5, 2, 12, 34, 56, 987, 654, 321] | ||
]; | ||
|
||
class MyDateTime extends Temporal.DateTime { | ||
constructor(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond) { | ||
assert.compareArray([year, month, day, hour, minute, second, millisecond, microsecond, nanosecond], constructorArguments.shift(), "constructor arguments"); | ||
++called; | ||
super(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond); | ||
} | ||
} | ||
|
||
const instance = MyDateTime.from("2000-05-02T12:34:56.987654321"); | ||
assert.sameValue(called, 1); | ||
|
||
const result = instance.getISOCalendarFields(); | ||
assert.sameValue(result.year, 2000, "year result"); | ||
assert.sameValue(result.month, 5, "month result"); | ||
assert.sameValue(result.day, 2, "day result"); | ||
assert.sameValue(result.hour, 12, "hour result"); | ||
assert.sameValue(result.minute, 34, "minute result"); | ||
assert.sameValue(result.second, 56, "second result"); | ||
assert.sameValue(result.millisecond, 987, "millisecond result"); | ||
assert.sameValue(result.microsecond, 654, "microsecond result"); | ||
assert.sameValue(result.nanosecond, 321, "nanosecond result"); | ||
assert.sameValue(called, 1); | ||
assert.sameValue(Object.getPrototypeOf(result), Object.prototype); |
Oops, something went wrong.