test262/test/built-ins/Temporal/PlainDate/compare/argument-plaindatetime.js

51 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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.plaindate.compare
description: Fast path for converting Temporal.PlainDateTime to Temporal.PlainDate by reading internal slots
info: |
sec-temporal.plaindate.compare steps 12:
1. Set _one_ to ? ToTemporalDate(_one_).
2. Set _two_ to ? ToTemporalDate(_two_).
sec-temporal-totemporaldate step 2.b:
b. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then
i. Return ! CreateTemporalDate(_item_.[[ISOYear]], _item_.[[ISOMonth]], _item_.[[ISODay]], _item_.[[Calendar]]).
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const sameDate = new Temporal.PlainDate(2000, 5, 2);
const earlierDate = new Temporal.PlainDate(1920, 7, 3);
const laterDate = new Temporal.PlainDate(2005, 1, 12);
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.compare(datetime, sameDate);
assert.sameValue(result, 0, "First argument, same date: comparison result");
}, "First argument, same date");
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.compare(datetime, earlierDate);
assert.sameValue(result, 1, "First argument, earlier date: comparison result");
}, "First argument, earlier date");
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.compare(datetime, laterDate);
assert.sameValue(result, -1, "First argument, later date: comparison result");
}, "First argument, later date");
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.compare(sameDate, datetime);
assert.sameValue(result, 0, "Second argument, same date: comparison result");
}, "Second argument, same date");
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.compare(earlierDate, datetime);
assert.sameValue(result, -1, "Second argument, earlier date: comparison result");
}, "Second argument, earlier date");
TemporalHelpers.checkPlainDateTimeConversionFastPath((datetime) => {
const result = Temporal.PlainDate.compare(laterDate, datetime);
assert.sameValue(result, 1, "Second argument, later date: comparison result");
}, "Second argument, later date");