mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 23:44:27 +02:00
Temporal: Remove Plain/ZonedDateTime to PlainYearMonth/MonthDay APIs
See tc39/proposal-temporal#2848
This commit is contained in:
parent
1c900ca59c
commit
3c28e3a359
@ -1,22 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: Throw a TypeError if the receiver is invalid
|
|
||||||
features: [Symbol, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const toPlainMonthDay = Temporal.PlainDateTime.prototype.toPlainMonthDay;
|
|
||||||
|
|
||||||
assert.sameValue(typeof toPlainMonthDay, "function");
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(undefined), "undefined");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(null), "null");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(true), "true");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(""), "empty string");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(Symbol()), "symbol");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(1), "1");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call({}), "plain object");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(Temporal.PlainDateTime), "Temporal.PlainDateTime");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(Temporal.PlainDateTime.prototype), "Temporal.PlainDateTime.prototype");
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable array iteration when getting the calendar fields.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
|
|
||||||
Array.prototype[Symbol.iterator] = function arrayIterator() {
|
|
||||||
throw new Test262Error("Array should not be iterated");
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new Temporal.PlainDateTime(2023, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
|
|
||||||
Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
|
|
@ -1,34 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable lookups or calls to calendar methods.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const fieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "fields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("fields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const monthDayFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "monthDayFromFields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "monthDayFromFields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("monthDayFromFields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", fieldsOriginal);
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "monthDayFromFields", monthDayFromFieldsOriginal);
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Tests that Temporal.PlainDateTime.prototype.toPlainMonthDay
|
|
||||||
meets the requirements for built-in objects defined by the
|
|
||||||
introduction of chapter 17 of the ECMAScript Language Specification.
|
|
||||||
info: |
|
|
||||||
Built-in functions that are not constructors do not have a "prototype" property unless
|
|
||||||
otherwise specified in the description of a particular function.
|
|
||||||
|
|
||||||
Unless specified otherwise, a built-in object that is callable as a function is a built-in
|
|
||||||
function object with the characteristics described in 10.3. Unless specified otherwise, the
|
|
||||||
[[Extensible]] internal slot of a built-in object initially has the value true.
|
|
||||||
|
|
||||||
Unless otherwise specified every built-in function and every built-in constructor has the
|
|
||||||
Function prototype object [...] as the value of its [[Prototype]] internal slot.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(Object.isExtensible(Temporal.PlainDateTime.prototype.toPlainMonthDay),
|
|
||||||
true, "Built-in objects must be extensible.");
|
|
||||||
|
|
||||||
assert.sameValue(Object.prototype.toString.call(Temporal.PlainDateTime.prototype.toPlainMonthDay),
|
|
||||||
"[object Function]", "Object.prototype.toString");
|
|
||||||
|
|
||||||
assert.sameValue(Object.getPrototypeOf(Temporal.PlainDateTime.prototype.toPlainMonthDay),
|
|
||||||
Function.prototype, "prototype");
|
|
||||||
|
|
||||||
assert.sameValue(Temporal.PlainDateTime.prototype.toPlainMonthDay.hasOwnProperty("prototype"),
|
|
||||||
false, "prototype property");
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: Correct options value is passed to calendar method
|
|
||||||
info: |
|
|
||||||
MonthDayFromFields ( calendar, fields [ , options ] )
|
|
||||||
|
|
||||||
3. If options is not present, then
|
|
||||||
a. Set options to undefined.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class CustomCalendar extends Temporal.Calendar {
|
|
||||||
constructor() {
|
|
||||||
super("iso8601");
|
|
||||||
}
|
|
||||||
monthDayFromFields(...args) {
|
|
||||||
assert.sameValue(args.length, 2, "args.length");
|
|
||||||
assert.sameValue(typeof args[0], "object", "args[0]");
|
|
||||||
assert.sameValue(args[1], undefined, "args[1]");
|
|
||||||
return super.monthDayFromFields(...args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 456, 789, new CustomCalendar());
|
|
||||||
const result = plainDateTime.toPlainMonthDay();
|
|
||||||
TemporalHelpers.assertPlainMonthDay(result, "M05", 2);
|
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: Verify the result of calendar.fields() is treated correctly.
|
|
||||||
info: |
|
|
||||||
sec-temporal.plaindatetime.prototype.toplainmonthday step 4:
|
|
||||||
4. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"monthCode"* »).
|
|
||||||
sec-temporal-calendarfields step 4:
|
|
||||||
4. Let _result_ be ? IterableToList(_fieldsArray_).
|
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
"day",
|
|
||||||
"monthCode",
|
|
||||||
];
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFieldsIterable();
|
|
||||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
|
||||||
datetime.toPlainMonthDay();
|
|
||||||
|
|
||||||
assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once");
|
|
||||||
assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args");
|
|
||||||
assert(calendar.iteratorExhausted[0], "iterated through the whole iterable");
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calendar.monthDayFromFields method is called with a null-prototype fields object
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution();
|
|
||||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
assert.sameValue(calendar.monthDayFromFieldsCallCount, 1, "monthDayFromFields should have been called on the calendar");
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calendar.monthDayFromFields method is called with undefined as the options
|
|
||||||
value when call originates internally
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFromFieldsUndefinedOptions();
|
|
||||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
assert.sameValue(calendar.monthDayFromFieldsCallCount, 1);
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']);
|
|
||||||
const datetime = new Temporal.PlainDateTime(2023, 5, 1, 0, 0, 0, 0, 0, 0, calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainMonthDay());
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
for (const extra_fields of [['foo', 'foo'], ['monthCode'], ['day']]) {
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields);
|
|
||||||
const datetime = new Temporal.PlainDateTime(2023, 5, 1, 0, 0, 0, 0, 0, 0, calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainMonthDay());
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
// 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.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: Temporal.PlainDateTime.prototype.toPlainMonthDay.length is 0
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, has a "length" property whose value is
|
|
||||||
an integer. Unless otherwise specified, this value is equal to the largest number of named
|
|
||||||
arguments shown in the subclause headings for the function description. Optional parameters
|
|
||||||
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
|
|
||||||
«...name») are not included in the default argument count.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "length" property of a built-in function object has the
|
|
||||||
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.PlainDateTime.prototype.toPlainMonthDay, "length", {
|
|
||||||
value: 0,
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: Temporal.PlainDateTime.prototype.toPlainMonthDay.name is "toPlainMonthDay".
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, that is not identified as an anonymous
|
|
||||||
function has a "name" property whose value is a String. Unless otherwise specified, this value
|
|
||||||
is the name that is given to the function in this specification.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
|
|
||||||
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.PlainDateTime.prototype.toPlainMonthDay, "name", {
|
|
||||||
value: "toPlainMonthDay",
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Temporal.PlainDateTime.prototype.toPlainMonthDay does not implement [[Construct]], is not new-able
|
|
||||||
info: |
|
|
||||||
Built-in function objects that are not identified as constructors do not implement the
|
|
||||||
[[Construct]] internal method unless otherwise specified in the description of a particular
|
|
||||||
function.
|
|
||||||
includes: [isConstructor.js]
|
|
||||||
features: [Reflect.construct, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => {
|
|
||||||
new Temporal.PlainDateTime.prototype.toPlainMonthDay();
|
|
||||||
}, "Calling as constructor");
|
|
||||||
|
|
||||||
assert.sameValue(isConstructor(Temporal.PlainDateTime.prototype.toPlainMonthDay), false,
|
|
||||||
"isConstructor(Temporal.PlainDateTime.prototype.toPlainMonthDay)");
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: The "toPlainMonthDay" property of Temporal.PlainDateTime.prototype
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
typeof Temporal.PlainDateTime.prototype.toPlainMonthDay,
|
|
||||||
"function",
|
|
||||||
"`typeof PlainDateTime.prototype.toPlainMonthDay` is `function`"
|
|
||||||
);
|
|
||||||
|
|
||||||
verifyProperty(Temporal.PlainDateTime.prototype, "toPlainMonthDay", {
|
|
||||||
writable: true,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainmonthday
|
|
||||||
description: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']);
|
|
||||||
const datetime = new Temporal.PlainDateTime(2023, 5, 1, 0, 0, 0, 0, 0, 0, calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainMonthDay());
|
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: Throw a TypeError if the receiver is invalid
|
|
||||||
features: [Symbol, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const toPlainYearMonth = Temporal.PlainDateTime.prototype.toPlainYearMonth;
|
|
||||||
|
|
||||||
assert.sameValue(typeof toPlainYearMonth, "function");
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(undefined), "undefined");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(null), "null");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(true), "true");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(""), "empty string");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(Symbol()), "symbol");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(1), "1");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call({}), "plain object");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(Temporal.PlainDateTime), "Temporal.PlainDateTime");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(Temporal.PlainDateTime.prototype), "Temporal.PlainDateTime.prototype");
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable array iteration when getting the calendar fields.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
|
|
||||||
Array.prototype[Symbol.iterator] = function arrayIterator() {
|
|
||||||
throw new Test262Error("Array should not be iterated");
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new Temporal.PlainDateTime(2023, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
|
|
||||||
Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
|
|
@ -1,34 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable lookups or calls to calendar methods.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const fieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "fields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("fields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const yearMonthFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "yearMonthFromFields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "yearMonthFromFields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("yearMonthFromFields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601");
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", fieldsOriginal);
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "yearMonthFromFields", yearMonthFromFieldsOriginal);
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Tests that Temporal.PlainDateTime.prototype.toPlainYearMonth
|
|
||||||
meets the requirements for built-in objects defined by the
|
|
||||||
introduction of chapter 17 of the ECMAScript Language Specification.
|
|
||||||
info: |
|
|
||||||
Built-in functions that are not constructors do not have a "prototype" property unless
|
|
||||||
otherwise specified in the description of a particular function.
|
|
||||||
|
|
||||||
Unless specified otherwise, a built-in object that is callable as a function is a built-in
|
|
||||||
function object with the characteristics described in 10.3. Unless specified otherwise, the
|
|
||||||
[[Extensible]] internal slot of a built-in object initially has the value true.
|
|
||||||
|
|
||||||
Unless otherwise specified every built-in function and every built-in constructor has the
|
|
||||||
Function prototype object [...] as the value of its [[Prototype]] internal slot.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(Object.isExtensible(Temporal.PlainDateTime.prototype.toPlainYearMonth),
|
|
||||||
true, "Built-in objects must be extensible.");
|
|
||||||
|
|
||||||
assert.sameValue(Object.prototype.toString.call(Temporal.PlainDateTime.prototype.toPlainYearMonth),
|
|
||||||
"[object Function]", "Object.prototype.toString");
|
|
||||||
|
|
||||||
assert.sameValue(Object.getPrototypeOf(Temporal.PlainDateTime.prototype.toPlainYearMonth),
|
|
||||||
Function.prototype, "prototype");
|
|
||||||
|
|
||||||
assert.sameValue(Temporal.PlainDateTime.prototype.toPlainYearMonth.hasOwnProperty("prototype"),
|
|
||||||
false, "prototype property");
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: Correct options value is passed to calendar method
|
|
||||||
info: |
|
|
||||||
YearMonthFromFields ( calendar, fields [ , options ] )
|
|
||||||
|
|
||||||
3. If options is not present, then
|
|
||||||
a. Set options to undefined.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class CustomCalendar extends Temporal.Calendar {
|
|
||||||
constructor() {
|
|
||||||
super("iso8601");
|
|
||||||
}
|
|
||||||
yearMonthFromFields(...args) {
|
|
||||||
assert.sameValue(args.length, 2, "args.length");
|
|
||||||
assert.sameValue(typeof args[0], "object", "args[0]");
|
|
||||||
assert.sameValue(args[1], undefined, "args[1]");
|
|
||||||
return super.yearMonthFromFields(...args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const plainDateTime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 456, 789, new CustomCalendar());
|
|
||||||
const result = plainDateTime.toPlainYearMonth();
|
|
||||||
TemporalHelpers.assertPlainYearMonth(result, 2000, 5, "M05");
|
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: Verify the result of calendar.fields() is treated correctly.
|
|
||||||
info: |
|
|
||||||
sec-temporal.plaindatetime.prototype.toplainyearmonth step 4:
|
|
||||||
4. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"monthCode"*, *"year"* »).
|
|
||||||
sec-temporal-calendarfields step 4:
|
|
||||||
4. Let _result_ be ? IterableToList(_fieldsArray_).
|
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
"monthCode",
|
|
||||||
"year",
|
|
||||||
];
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFieldsIterable();
|
|
||||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
|
||||||
datetime.toPlainYearMonth();
|
|
||||||
|
|
||||||
assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once");
|
|
||||||
assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args");
|
|
||||||
assert(calendar.iteratorExhausted[0], "iterated through the whole iterable");
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calendar.yearMonthFromFields method is called with a null-prototype fields object
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution();
|
|
||||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
assert.sameValue(calendar.yearMonthFromFieldsCallCount, 1, "yearMonthFromFields should have been called on the calendar");
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calendar.yearMonthFromFields method is called with undefined as the options
|
|
||||||
value when call originates internally
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFromFieldsUndefinedOptions();
|
|
||||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar);
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
assert.sameValue(calendar.yearMonthFromFieldsCallCount, 1);
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']);
|
|
||||||
const datetime = new Temporal.PlainDateTime(2023, 5, 1, 0, 0, 0, 0, 0, 0, calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainYearMonth());
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
for (const extra_fields of [['foo', 'foo'], ['monthCode'], ['year']]) {
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields);
|
|
||||||
const datetime = new Temporal.PlainDateTime(2023, 5, 1, 0, 0, 0, 0, 0, 0, calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainYearMonth());
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
// 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.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: Temporal.PlainDateTime.prototype.toPlainYearMonth.length is 0
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, has a "length" property whose value is
|
|
||||||
an integer. Unless otherwise specified, this value is equal to the largest number of named
|
|
||||||
arguments shown in the subclause headings for the function description. Optional parameters
|
|
||||||
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
|
|
||||||
«...name») are not included in the default argument count.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "length" property of a built-in function object has the
|
|
||||||
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.PlainDateTime.prototype.toPlainYearMonth, "length", {
|
|
||||||
value: 0,
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: Temporal.PlainDateTime.prototype.toPlainYearMonth.name is "toPlainYearMonth".
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, that is not identified as an anonymous
|
|
||||||
function has a "name" property whose value is a String. Unless otherwise specified, this value
|
|
||||||
is the name that is given to the function in this specification.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
|
|
||||||
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.PlainDateTime.prototype.toPlainYearMonth, "name", {
|
|
||||||
value: "toPlainYearMonth",
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Temporal.PlainDateTime.prototype.toPlainYearMonth does not implement [[Construct]], is not new-able
|
|
||||||
info: |
|
|
||||||
Built-in function objects that are not identified as constructors do not implement the
|
|
||||||
[[Construct]] internal method unless otherwise specified in the description of a particular
|
|
||||||
function.
|
|
||||||
includes: [isConstructor.js]
|
|
||||||
features: [Reflect.construct, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => {
|
|
||||||
new Temporal.PlainDateTime.prototype.toPlainYearMonth();
|
|
||||||
}, "Calling as constructor");
|
|
||||||
|
|
||||||
assert.sameValue(isConstructor(Temporal.PlainDateTime.prototype.toPlainYearMonth), false,
|
|
||||||
"isConstructor(Temporal.PlainDateTime.prototype.toPlainYearMonth)");
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: The "toPlainYearMonth" property of Temporal.PlainDateTime.prototype
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
typeof Temporal.PlainDateTime.prototype.toPlainYearMonth,
|
|
||||||
"function",
|
|
||||||
"`typeof PlainDateTime.prototype.toPlainYearMonth` is `function`"
|
|
||||||
);
|
|
||||||
|
|
||||||
verifyProperty(Temporal.PlainDateTime.prototype, "toPlainYearMonth", {
|
|
||||||
writable: true,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.plaindatetime.prototype.toplainyearmonth
|
|
||||||
description: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']);
|
|
||||||
const datetime = new Temporal.PlainDateTime(2023, 5, 1, 0, 0, 0, 0, 0, 0, calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainYearMonth());
|
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: Throw a TypeError if the receiver is invalid
|
|
||||||
features: [Symbol, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const toPlainMonthDay = Temporal.ZonedDateTime.prototype.toPlainMonthDay;
|
|
||||||
|
|
||||||
assert.sameValue(typeof toPlainMonthDay, "function");
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(undefined), "undefined");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(null), "null");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(true), "true");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(""), "empty string");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(Symbol()), "symbol");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(1), "1");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call({}), "plain object");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(Temporal.ZonedDateTime), "Temporal.ZonedDateTime");
|
|
||||||
assert.throws(TypeError, () => toPlainMonthDay.call(Temporal.ZonedDateTime.prototype), "Temporal.ZonedDateTime.prototype");
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable array iteration when getting the calendar fields.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
|
|
||||||
Array.prototype[Symbol.iterator] = function arrayIterator() {
|
|
||||||
throw new Test262Error("Array should not be iterated");
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
|
|
||||||
Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
|
|
@ -1,34 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable lookups or calls to calendar methods.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const fieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "fields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("fields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const monthDayFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "monthDayFromFields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "monthDayFromFields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("monthDayFromFields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", fieldsOriginal);
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "monthDayFromFields", monthDayFromFieldsOriginal);
|
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin time zone causes
|
|
||||||
no observable lookups or calls to time zone methods.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
|
|
||||||
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
|
|
||||||
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Tests that Temporal.ZonedDateTime.prototype.toPlainMonthDay
|
|
||||||
meets the requirements for built-in objects defined by the
|
|
||||||
introduction of chapter 17 of the ECMAScript Language Specification.
|
|
||||||
info: |
|
|
||||||
Built-in functions that are not constructors do not have a "prototype" property unless
|
|
||||||
otherwise specified in the description of a particular function.
|
|
||||||
|
|
||||||
Unless specified otherwise, a built-in object that is callable as a function is a built-in
|
|
||||||
function object with the characteristics described in 10.3. Unless specified otherwise, the
|
|
||||||
[[Extensible]] internal slot of a built-in object initially has the value true.
|
|
||||||
|
|
||||||
Unless otherwise specified every built-in function and every built-in constructor has the
|
|
||||||
Function prototype object [...] as the value of its [[Prototype]] internal slot.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(Object.isExtensible(Temporal.ZonedDateTime.prototype.toPlainMonthDay),
|
|
||||||
true, "Built-in objects must be extensible.");
|
|
||||||
|
|
||||||
assert.sameValue(Object.prototype.toString.call(Temporal.ZonedDateTime.prototype.toPlainMonthDay),
|
|
||||||
"[object Function]", "Object.prototype.toString");
|
|
||||||
|
|
||||||
assert.sameValue(Object.getPrototypeOf(Temporal.ZonedDateTime.prototype.toPlainMonthDay),
|
|
||||||
Function.prototype, "prototype");
|
|
||||||
|
|
||||||
assert.sameValue(Temporal.ZonedDateTime.prototype.toPlainMonthDay.hasOwnProperty("prototype"),
|
|
||||||
false, "prototype property");
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: Correct options value is passed to calendar method
|
|
||||||
info: |
|
|
||||||
MonthDayFromFields ( calendar, fields [ , options ] )
|
|
||||||
|
|
||||||
3. If options is not present, then
|
|
||||||
a. Set options to undefined.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class CustomCalendar extends Temporal.Calendar {
|
|
||||||
constructor() {
|
|
||||||
super("iso8601");
|
|
||||||
}
|
|
||||||
monthDayFromFields(...args) {
|
|
||||||
assert.sameValue(args.length, 2, "args.length");
|
|
||||||
assert.sameValue(typeof args[0], "object", "args[0]");
|
|
||||||
assert.sameValue(args[1], undefined, "args[1]");
|
|
||||||
return super.monthDayFromFields(...args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const zonedDateTime = new Temporal.ZonedDateTime(957270896123456789n, "UTC", new CustomCalendar());
|
|
||||||
const result = zonedDateTime.toPlainMonthDay();
|
|
||||||
TemporalHelpers.assertPlainMonthDay(result, "M05", 2);
|
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: Verify the result of calendar.fields() is treated correctly.
|
|
||||||
info: |
|
|
||||||
sec-temporal.zoneddatetime.prototype.toplainmonthday step 7:
|
|
||||||
7. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"monthCode"* »).
|
|
||||||
sec-temporal-calendarfields step 4:
|
|
||||||
4. Let _result_ be ? IterableToList(_fieldsArray_).
|
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
"day",
|
|
||||||
"monthCode",
|
|
||||||
];
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFieldsIterable();
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
|
|
||||||
datetime.toPlainMonthDay();
|
|
||||||
|
|
||||||
assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once");
|
|
||||||
assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args");
|
|
||||||
assert(calendar.iteratorExhausted[0], "iterated through the whole iterable");
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calendar.monthDayFromFields method is called with a null-prototype fields object
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution();
|
|
||||||
const instance = new Temporal.ZonedDateTime(0n, "UTC", calendar);
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
assert.sameValue(calendar.monthDayFromFieldsCallCount, 1, "monthDayFromFields should have been called on the calendar");
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Calendar.monthDayFromFields method is called with undefined as the options
|
|
||||||
value when call originates internally
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFromFieldsUndefinedOptions();
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
assert.sameValue(calendar.monthDayFromFieldsCallCount, 1);
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: TypeError thrown when calendar method returns an object with the wrong brand
|
|
||||||
info: |
|
|
||||||
MonthDayFromFields ( calendar, fields, options )
|
|
||||||
|
|
||||||
4. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class CustomCalendar extends Temporal.Calendar {
|
|
||||||
constructor() {
|
|
||||||
super("iso8601");
|
|
||||||
}
|
|
||||||
monthDayFromFields() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const zonedDateTime = new Temporal.ZonedDateTime(957270896123456789n, "UTC", new CustomCalendar());
|
|
||||||
assert.throws(TypeError, () => zonedDateTime.toPlainMonthDay());
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']);
|
|
||||||
const zoneddatetime = new Temporal.ZonedDateTime(1682892000000000000n, 'Europe/Madrid', calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => zoneddatetime.toPlainMonthDay());
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
for (const extra_fields of [['foo', 'foo'], ['monthCode'], ['day']]) {
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields);
|
|
||||||
const zoneddatetime = new Temporal.ZonedDateTime(1682892000000000000n, 'Europe/Madrid', calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => zoneddatetime.toPlainMonthDay());
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: Temporal.ZonedDateTime.prototype.toPlainMonthDay.length is 0
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, has a "length" property whose value is
|
|
||||||
an integer. Unless otherwise specified, this value is equal to the largest number of named
|
|
||||||
arguments shown in the subclause headings for the function description. Optional parameters
|
|
||||||
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
|
|
||||||
«...name») are not included in the default argument count.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "length" property of a built-in function object has the
|
|
||||||
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.ZonedDateTime.prototype.toPlainMonthDay, "length", {
|
|
||||||
value: 0,
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: Temporal.ZonedDateTime.prototype.toPlainMonthDay.name is "toPlainMonthDay".
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, that is not identified as an anonymous
|
|
||||||
function has a "name" property whose value is a String. Unless otherwise specified, this value
|
|
||||||
is the name that is given to the function in this specification.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
|
|
||||||
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.ZonedDateTime.prototype.toPlainMonthDay, "name", {
|
|
||||||
value: "toPlainMonthDay",
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
Temporal.ZonedDateTime.prototype.toPlainMonthDay does not implement [[Construct]], is not new-able
|
|
||||||
info: |
|
|
||||||
Built-in function objects that are not identified as constructors do not implement the
|
|
||||||
[[Construct]] internal method unless otherwise specified in the description of a particular
|
|
||||||
function.
|
|
||||||
includes: [isConstructor.js]
|
|
||||||
features: [Reflect.construct, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => {
|
|
||||||
new Temporal.ZonedDateTime.prototype.toPlainMonthDay();
|
|
||||||
}, "Calling as constructor");
|
|
||||||
|
|
||||||
assert.sameValue(isConstructor(Temporal.ZonedDateTime.prototype.toPlainMonthDay), false,
|
|
||||||
"isConstructor(Temporal.ZonedDateTime.prototype.toPlainMonthDay)");
|
|
@ -1,48 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: >
|
|
||||||
User-observable time zone and calendar accesses and calls in
|
|
||||||
toPlainMonthDay() happen the correct order
|
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
"get this.calendar.fields",
|
|
||||||
"get this.calendar.monthDayFromFields",
|
|
||||||
"get this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.calendar.fields",
|
|
||||||
"get this.calendar.day",
|
|
||||||
"call this.calendar.day",
|
|
||||||
"get this.calendar.monthCode",
|
|
||||||
"call this.calendar.monthCode",
|
|
||||||
"call this.calendar.monthDayFromFields",
|
|
||||||
];
|
|
||||||
const actual = [];
|
|
||||||
|
|
||||||
const timeZone = TemporalHelpers.timeZoneObserver(actual, "this.timeZone");
|
|
||||||
const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar");
|
|
||||||
const instance = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|
||||||
Object.defineProperties(instance, {
|
|
||||||
day: {
|
|
||||||
get() {
|
|
||||||
actual.push("get this.day");
|
|
||||||
return TemporalHelpers.toPrimitiveObserver(actual, 1, "this.day");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
monthCode: {
|
|
||||||
get() {
|
|
||||||
actual.push("get this.monthCode");
|
|
||||||
return TemporalHelpers.toPrimitiveObserver(actual, "M01", "this.monthCode");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// clear observable operations that occurred during the constructor call
|
|
||||||
actual.splice(0);
|
|
||||||
|
|
||||||
instance.toPlainMonthDay();
|
|
||||||
assert.compareArray(actual, expected, "order of operations");
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: The "toPlainMonthDay" property of Temporal.ZonedDateTime.prototype
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
typeof Temporal.ZonedDateTime.prototype.toPlainMonthDay,
|
|
||||||
"function",
|
|
||||||
"`typeof ZonedDateTime.prototype.toPlainMonthDay` is `function`"
|
|
||||||
);
|
|
||||||
|
|
||||||
verifyProperty(Temporal.ZonedDateTime.prototype, "toPlainMonthDay", {
|
|
||||||
writable: true,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']);
|
|
||||||
const zoneddatetime = new Temporal.ZonedDateTime(1682892000000000000n, 'Europe/Madrid', calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => zoneddatetime.toPlainMonthDay());
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
|
|
||||||
features: [Temporal]
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
|
|
||||||
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainMonthDay());
|
|
||||||
});
|
|
@ -1,19 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable
|
|
||||||
features: [BigInt, Symbol, Temporal, arrow-function]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => {
|
|
||||||
const timeZone = new Temporal.TimeZone("UTC");
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
timeZone.getOffsetNanosecondsFor = notCallable;
|
|
||||||
assert.throws(
|
|
||||||
TypeError,
|
|
||||||
() => datetime.toPlainMonthDay(),
|
|
||||||
`Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError`
|
|
||||||
);
|
|
||||||
});
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: RangeError thrown if time zone reports an offset that is out of range
|
|
||||||
features: [Temporal]
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => {
|
|
||||||
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainMonthDay());
|
|
||||||
});
|
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainmonthday
|
|
||||||
description: TypeError thrown if time zone reports an offset that is not a Number
|
|
||||||
features: [Temporal]
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[
|
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
"+01:00",
|
|
||||||
Symbol(),
|
|
||||||
3600_000_000_000n,
|
|
||||||
{},
|
|
||||||
{ valueOf() { return 3600_000_000_000; } },
|
|
||||||
].forEach((wrongOffset) => {
|
|
||||||
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
assert.throws(TypeError, () => datetime.toPlainMonthDay());
|
|
||||||
});
|
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: Throw a TypeError if the receiver is invalid
|
|
||||||
features: [Symbol, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const toPlainYearMonth = Temporal.ZonedDateTime.prototype.toPlainYearMonth;
|
|
||||||
|
|
||||||
assert.sameValue(typeof toPlainYearMonth, "function");
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(undefined), "undefined");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(null), "null");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(true), "true");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(""), "empty string");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(Symbol()), "symbol");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(1), "1");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call({}), "plain object");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(Temporal.ZonedDateTime), "Temporal.ZonedDateTime");
|
|
||||||
assert.throws(TypeError, () => toPlainYearMonth.call(Temporal.ZonedDateTime.prototype), "Temporal.ZonedDateTime.prototype");
|
|
@ -1,20 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable array iteration when getting the calendar fields.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator];
|
|
||||||
Array.prototype[Symbol.iterator] = function arrayIterator() {
|
|
||||||
throw new Test262Error("Array should not be iterated");
|
|
||||||
}
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
|
|
||||||
Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal;
|
|
@ -1,34 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin calendar causes
|
|
||||||
no observable lookups or calls to calendar methods.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const fieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "fields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("fields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const yearMonthFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "yearMonthFromFields");
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "yearMonthFromFields", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("yearMonthFromFields should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "fields", fieldsOriginal);
|
|
||||||
Object.defineProperty(Temporal.Calendar.prototype, "yearMonthFromFields", yearMonthFromFieldsOriginal);
|
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calling the method on an instance constructed with a builtin time zone causes
|
|
||||||
no observable lookups or calls to time zone methods.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
|
|
||||||
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
|
|
||||||
configurable: true,
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
|
|
||||||
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);
|
|
@ -1,33 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Tests that Temporal.ZonedDateTime.prototype.toPlainYearMonth
|
|
||||||
meets the requirements for built-in objects defined by the
|
|
||||||
introduction of chapter 17 of the ECMAScript Language Specification.
|
|
||||||
info: |
|
|
||||||
Built-in functions that are not constructors do not have a "prototype" property unless
|
|
||||||
otherwise specified in the description of a particular function.
|
|
||||||
|
|
||||||
Unless specified otherwise, a built-in object that is callable as a function is a built-in
|
|
||||||
function object with the characteristics described in 10.3. Unless specified otherwise, the
|
|
||||||
[[Extensible]] internal slot of a built-in object initially has the value true.
|
|
||||||
|
|
||||||
Unless otherwise specified every built-in function and every built-in constructor has the
|
|
||||||
Function prototype object [...] as the value of its [[Prototype]] internal slot.
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(Object.isExtensible(Temporal.ZonedDateTime.prototype.toPlainYearMonth),
|
|
||||||
true, "Built-in objects must be extensible.");
|
|
||||||
|
|
||||||
assert.sameValue(Object.prototype.toString.call(Temporal.ZonedDateTime.prototype.toPlainYearMonth),
|
|
||||||
"[object Function]", "Object.prototype.toString");
|
|
||||||
|
|
||||||
assert.sameValue(Object.getPrototypeOf(Temporal.ZonedDateTime.prototype.toPlainYearMonth),
|
|
||||||
Function.prototype, "prototype");
|
|
||||||
|
|
||||||
assert.sameValue(Temporal.ZonedDateTime.prototype.toPlainYearMonth.hasOwnProperty("prototype"),
|
|
||||||
false, "prototype property");
|
|
@ -1,29 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: Correct options value is passed to calendar method
|
|
||||||
info: |
|
|
||||||
YearMonthFromFields ( calendar, fields [ , options ] )
|
|
||||||
|
|
||||||
3. If options is not present, then
|
|
||||||
a. Set options to undefined.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class CustomCalendar extends Temporal.Calendar {
|
|
||||||
constructor() {
|
|
||||||
super("iso8601");
|
|
||||||
}
|
|
||||||
yearMonthFromFields(...args) {
|
|
||||||
assert.sameValue(args.length, 2, "args.length");
|
|
||||||
assert.sameValue(typeof args[0], "object", "args[0]");
|
|
||||||
assert.sameValue(args[1], undefined, "args[1]");
|
|
||||||
return super.yearMonthFromFields(...args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const zonedDateTime = new Temporal.ZonedDateTime(957270896123456789n, "UTC", new CustomCalendar());
|
|
||||||
const result = zonedDateTime.toPlainYearMonth();
|
|
||||||
TemporalHelpers.assertPlainYearMonth(result, 2000, 5, "M05");
|
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: Verify the result of calendar.fields() is treated correctly.
|
|
||||||
info: |
|
|
||||||
sec-temporal.zoneddatetime.prototype.toplainyearmonth step 7:
|
|
||||||
7. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"monthCode"*, *"year"* »).
|
|
||||||
sec-temporal-calendarfields step 4:
|
|
||||||
4. Let _result_ be ? IterableToList(_fieldsArray_).
|
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
"monthCode",
|
|
||||||
"year",
|
|
||||||
];
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFieldsIterable();
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
|
|
||||||
datetime.toPlainYearMonth();
|
|
||||||
|
|
||||||
assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once");
|
|
||||||
assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args");
|
|
||||||
assert(calendar.iteratorExhausted[0], "iterated through the whole iterable");
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calendar.yearMonthFromFields method is called with a null-prototype fields object
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution();
|
|
||||||
const instance = new Temporal.ZonedDateTime(0n, "UTC", calendar);
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
assert.sameValue(calendar.yearMonthFromFieldsCallCount, 1, "yearMonthFromFields should have been called on the calendar");
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: TypeError thrown when calendar method returns an object with the wrong brand
|
|
||||||
info: |
|
|
||||||
YearMonthFromFields ( calendar, fields [ , options ] )
|
|
||||||
|
|
||||||
4. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
class CustomCalendar extends Temporal.Calendar {
|
|
||||||
constructor() {
|
|
||||||
super("iso8601");
|
|
||||||
}
|
|
||||||
yearMonthFromFields() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const zonedDateTime = new Temporal.ZonedDateTime(957270896123456789n, "UTC", new CustomCalendar());
|
|
||||||
assert.throws(TypeError, () => zonedDateTime.toPlainYearMonth());
|
|
@ -1,16 +0,0 @@
|
|||||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Calendar.yearMonthFromFields method is called with undefined as the options
|
|
||||||
value when call originates internally
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarFromFieldsUndefinedOptions();
|
|
||||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
assert.sameValue(calendar.yearMonthFromFieldsCallCount, 1);
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']);
|
|
||||||
const zoneddatetime = new Temporal.ZonedDateTime(1682892000000000000n, 'Europe/Madrid', calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => zoneddatetime.toPlainYearMonth());
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
for (const extra_fields of [['foo', 'foo'], ['monthCode'], ['year']]) {
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields);
|
|
||||||
const zoneddatetime = new Temporal.ZonedDateTime(1682892000000000000n, 'Europe/Madrid', calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => zoneddatetime.toPlainYearMonth());
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: Temporal.ZonedDateTime.prototype.toPlainYearMonth.length is 0
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, has a "length" property whose value is
|
|
||||||
an integer. Unless otherwise specified, this value is equal to the largest number of named
|
|
||||||
arguments shown in the subclause headings for the function description. Optional parameters
|
|
||||||
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
|
|
||||||
«...name») are not included in the default argument count.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "length" property of a built-in function object has the
|
|
||||||
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.ZonedDateTime.prototype.toPlainYearMonth, "length", {
|
|
||||||
value: 0,
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,23 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: Temporal.ZonedDateTime.prototype.toPlainYearMonth.name is "toPlainYearMonth".
|
|
||||||
info: |
|
|
||||||
Every built-in function object, including constructors, that is not identified as an anonymous
|
|
||||||
function has a "name" property whose value is a String. Unless otherwise specified, this value
|
|
||||||
is the name that is given to the function in this specification.
|
|
||||||
|
|
||||||
Unless otherwise specified, the "name" property of a built-in function object, if it exists,
|
|
||||||
has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
verifyProperty(Temporal.ZonedDateTime.prototype.toPlainYearMonth, "name", {
|
|
||||||
value: "toPlainYearMonth",
|
|
||||||
writable: false,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
Temporal.ZonedDateTime.prototype.toPlainYearMonth does not implement [[Construct]], is not new-able
|
|
||||||
info: |
|
|
||||||
Built-in function objects that are not identified as constructors do not implement the
|
|
||||||
[[Construct]] internal method unless otherwise specified in the description of a particular
|
|
||||||
function.
|
|
||||||
includes: [isConstructor.js]
|
|
||||||
features: [Reflect.construct, Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.throws(TypeError, () => {
|
|
||||||
new Temporal.ZonedDateTime.prototype.toPlainYearMonth();
|
|
||||||
}, "Calling as constructor");
|
|
||||||
|
|
||||||
assert.sameValue(isConstructor(Temporal.ZonedDateTime.prototype.toPlainYearMonth), false,
|
|
||||||
"isConstructor(Temporal.ZonedDateTime.prototype.toPlainYearMonth)");
|
|
@ -1,48 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: >
|
|
||||||
User-observable time zone and calendar accesses and calls in
|
|
||||||
toPlainYearMonth() happen the correct order
|
|
||||||
includes: [compareArray.js, temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const expected = [
|
|
||||||
"get this.calendar.fields",
|
|
||||||
"get this.calendar.yearMonthFromFields",
|
|
||||||
"get this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.timeZone.getOffsetNanosecondsFor",
|
|
||||||
"call this.calendar.fields",
|
|
||||||
"get this.calendar.monthCode",
|
|
||||||
"call this.calendar.monthCode",
|
|
||||||
"get this.calendar.year",
|
|
||||||
"call this.calendar.year",
|
|
||||||
"call this.calendar.yearMonthFromFields",
|
|
||||||
];
|
|
||||||
const actual = [];
|
|
||||||
|
|
||||||
const timeZone = TemporalHelpers.timeZoneObserver(actual, "this.timeZone");
|
|
||||||
const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar");
|
|
||||||
const instance = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|
||||||
Object.defineProperties(instance, {
|
|
||||||
monthCode: {
|
|
||||||
get() {
|
|
||||||
actual.push("get this.monthCode");
|
|
||||||
return TemporalHelpers.toPrimitiveObserver(actual, "M01", "this.monthCode");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
year: {
|
|
||||||
get() {
|
|
||||||
actual.push("get this.year");
|
|
||||||
return TemporalHelpers.toPrimitiveObserver(actual, 1970, "this.year");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
// clear observable operations that occurred during the constructor call
|
|
||||||
actual.splice(0);
|
|
||||||
|
|
||||||
instance.toPlainYearMonth();
|
|
||||||
assert.compareArray(actual, expected, "order of operations");
|
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: The "toPlainYearMonth" property of Temporal.ZonedDateTime.prototype
|
|
||||||
includes: [propertyHelper.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
typeof Temporal.ZonedDateTime.prototype.toPlainYearMonth,
|
|
||||||
"function",
|
|
||||||
"`typeof ZonedDateTime.prototype.toPlainYearMonth` is `function`"
|
|
||||||
);
|
|
||||||
|
|
||||||
verifyProperty(Temporal.ZonedDateTime.prototype, "toPlainYearMonth", {
|
|
||||||
writable: true,
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
@ -1,13 +0,0 @@
|
|||||||
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError.
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']);
|
|
||||||
const zoneddatetime = new Temporal.ZonedDateTime(1682892000000000000n, 'Europe/Madrid', calendar);
|
|
||||||
|
|
||||||
assert.throws(RangeError, () => zoneddatetime.toPlainYearMonth());
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
|
|
||||||
features: [Temporal]
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => {
|
|
||||||
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainYearMonth());
|
|
||||||
});
|
|
@ -1,19 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable
|
|
||||||
features: [BigInt, Symbol, Temporal, arrow-function]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => {
|
|
||||||
const timeZone = new Temporal.TimeZone("UTC");
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
timeZone.getOffsetNanosecondsFor = notCallable;
|
|
||||||
assert.throws(
|
|
||||||
TypeError,
|
|
||||||
() => datetime.toPlainYearMonth(),
|
|
||||||
`Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError`
|
|
||||||
);
|
|
||||||
});
|
|
@ -1,15 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: RangeError thrown if time zone reports an offset that is out of range
|
|
||||||
features: [Temporal]
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => {
|
|
||||||
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
assert.throws(RangeError, () => datetime.toPlainYearMonth());
|
|
||||||
});
|
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal.zoneddatetime.prototype.toplainyearmonth
|
|
||||||
description: TypeError thrown if time zone reports an offset that is not a Number
|
|
||||||
features: [Temporal]
|
|
||||||
includes: [temporalHelpers.js]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
[
|
|
||||||
undefined,
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
"+01:00",
|
|
||||||
Symbol(),
|
|
||||||
3600_000_000_000n,
|
|
||||||
{},
|
|
||||||
{ valueOf() { return 3600_000_000_000; } },
|
|
||||||
].forEach((wrongOffset) => {
|
|
||||||
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);
|
|
||||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
|
||||||
assert.throws(TypeError, () => datetime.toPlainYearMonth());
|
|
||||||
});
|
|
@ -1,48 +0,0 @@
|
|||||||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal-zoneddatetime-objects
|
|
||||||
description: Temporal.ZonedDateTime.prototype.toPlainMonthDay()
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var tz = new Temporal.TimeZone("-08:00");
|
|
||||||
|
|
||||||
// works
|
|
||||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz);
|
|
||||||
assert.sameValue(`${ zdt.toPlainMonthDay() }`, "10-29");
|
|
||||||
|
|
||||||
// preserves the calendar
|
|
||||||
var fakeGregorian = {
|
|
||||||
id: 'gregory',
|
|
||||||
monthDayFromFields(fields) {
|
|
||||||
var md = Temporal.Calendar.from("iso8601").monthDayFromFields(fields);
|
|
||||||
var {isoYear, isoMonth, isoDay} = md.getISOFields();
|
|
||||||
return new Temporal.PlainMonthDay(isoMonth, isoDay, this, isoYear);
|
|
||||||
},
|
|
||||||
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
|
|
||||||
day(date) { return date.withCalendar("iso8601").day; },
|
|
||||||
dateAdd() {},
|
|
||||||
dateFromFields() {},
|
|
||||||
dateUntil() {},
|
|
||||||
dayOfWeek() {},
|
|
||||||
dayOfYear() {},
|
|
||||||
daysInMonth() {},
|
|
||||||
daysInWeek() {},
|
|
||||||
daysInYear() {},
|
|
||||||
fields(fieldNames) { return fieldNames; },
|
|
||||||
inLeapYear() {},
|
|
||||||
mergeFields() {},
|
|
||||||
month() {},
|
|
||||||
monthsInYear() {},
|
|
||||||
weekOfYear() {},
|
|
||||||
year() {},
|
|
||||||
yearMonthFromFields() {},
|
|
||||||
yearOfWeek() {},
|
|
||||||
};
|
|
||||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({
|
|
||||||
timeZone: tz,
|
|
||||||
calendar: fakeGregorian
|
|
||||||
});
|
|
||||||
assert.sameValue(zdt.toPlainMonthDay().getCalendar(), fakeGregorian);
|
|
@ -1,48 +0,0 @@
|
|||||||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/*---
|
|
||||||
esid: sec-temporal-zoneddatetime-objects
|
|
||||||
description: Temporal.ZonedDateTime.prototype.toPlainYearMonth()
|
|
||||||
features: [Temporal]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var tz = new Temporal.TimeZone("-08:00");
|
|
||||||
|
|
||||||
// works
|
|
||||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTimeISO(tz);
|
|
||||||
assert.sameValue(`${ zdt.toPlainYearMonth() }`, "2019-10");
|
|
||||||
|
|
||||||
// preserves the calendar
|
|
||||||
var fakeGregorian = {
|
|
||||||
id: 'gregory',
|
|
||||||
yearMonthFromFields(fields) {
|
|
||||||
var ym = Temporal.Calendar.from("iso8601").yearMonthFromFields(fields);
|
|
||||||
var {isoYear, isoMonth, isoDay} = ym.getISOFields();
|
|
||||||
return new Temporal.PlainYearMonth(isoYear, isoMonth, this, isoDay);
|
|
||||||
},
|
|
||||||
year(date) { return date.withCalendar("iso8601").year; },
|
|
||||||
monthCode(date) { return date.withCalendar("iso8601").monthCode; },
|
|
||||||
dateAdd() {},
|
|
||||||
dateFromFields() {},
|
|
||||||
dateUntil() {},
|
|
||||||
day() {},
|
|
||||||
dayOfWeek() {},
|
|
||||||
dayOfYear() {},
|
|
||||||
daysInMonth() {},
|
|
||||||
daysInWeek() {},
|
|
||||||
daysInYear() {},
|
|
||||||
fields(fieldNames) { return fieldNames; },
|
|
||||||
inLeapYear() {},
|
|
||||||
mergeFields() {},
|
|
||||||
month() {},
|
|
||||||
monthDayFromFields() {},
|
|
||||||
monthsInYear() {},
|
|
||||||
weekOfYear() {},
|
|
||||||
yearOfWeek() {},
|
|
||||||
};
|
|
||||||
var zdt = Temporal.Instant.from("2019-10-29T09:46:38.271986102Z").toZonedDateTime({
|
|
||||||
timeZone: tz,
|
|
||||||
calendar: fakeGregorian
|
|
||||||
});
|
|
||||||
assert.sameValue(zdt.toPlainYearMonth().getCalendar(), fakeGregorian);
|
|
Loading…
x
Reference in New Issue
Block a user