mirror of
https://github.com/tc39/test262.git
synced 2025-09-24 10:38:30 +02:00
In several tests involving custom calendars, we need to change the implementation of dateFromFields/monthDayFromFields/yearMonthFromFields so that the returned object gets the receiver as its calendar after chaining up to the builtin implementation. Normative PR: https://github.com/tc39/proposal-temporal/pull/2482
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
// 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.compare
|
|
description: A calendar ID is valid input for Calendar
|
|
includes: [temporalHelpers.js]
|
|
features: [Temporal]
|
|
---*/
|
|
|
|
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields");
|
|
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", {
|
|
configurable: true,
|
|
enumerable: false,
|
|
get() {
|
|
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up");
|
|
},
|
|
});
|
|
|
|
const calendar = "iso8601";
|
|
|
|
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
|
|
|
const result1 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18));
|
|
assert.sameValue(result1, 0, `Calendar created from string "${arg}" (first argument)`);
|
|
|
|
const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg);
|
|
assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`);
|
|
|
|
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal);
|