mirror of
https://github.com/tc39/test262.git
synced 2025-07-31 01:44:54 +02:00
An object may be given in any context where a Temporal.Instant is expected (see ToTemporalInstant). There is no conversion from a property bag to an Instant, unlike with other Temporal types. Instead the object is converted to a string, and if its toString() method yields a valid ISO string, the conversion succeeds. (An object with the default Object.prototype.toString will not.)
23 lines
959 B
JavaScript
23 lines
959 B
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.instant.compare
|
|
description: Object is converted to a string, then to Temporal.Instant
|
|
features: [Temporal]
|
|
---*/
|
|
|
|
const epoch = new Temporal.Instant(0n);
|
|
|
|
const arg = {};
|
|
assert.throws(RangeError, () => Temporal.Instant.compare(arg, epoch), "[object Object] is not a valid ISO string (first argument)");
|
|
assert.throws(RangeError, () => Temporal.Instant.compare(epoch, arg), "[object Object] is not a valid ISO string (second argument)");
|
|
|
|
arg.toString = function() {
|
|
return "1970-01-01T00:00Z";
|
|
};
|
|
const result1 = Temporal.Instant.compare(arg, epoch);
|
|
assert.sameValue(result1, 0, "result of toString is interpreted as ISO string (first argument)");
|
|
const result2 = Temporal.Instant.compare(epoch, arg);
|
|
assert.sameValue(result2, 0, "result of toString is interpreted as ISO string (second argument)");
|