| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2021 Igalia, S.L. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-temporal.zoneddatetime.from |
| 7 |
description: Verify that undefined options are handled correctly. |
| 8 |
features: [Temporal] |
| 9 |
---*/ |
| 10 |
|
| 11 |
const overflowFields = { year: 2000, month: 13, day: 2, timeZone: "UTC" }; |
| 12 |
|
| 13 |
const overflowExplicit = Temporal.ZonedDateTime.from(overflowFields, undefined); |
| 14 |
assert.sameValue(overflowExplicit.month, 12, "default overflow is constrain"); |
| 15 |
|
| 16 |
const overflowPropertyImplicit = Temporal.ZonedDateTime.from(overflowFields, {}); |
| 17 |
assert.sameValue(overflowPropertyImplicit.month, 12, "default overflow is constrain"); |
| 18 |
|
| 19 |
const overflowImplicit = Temporal.ZonedDateTime.from(overflowFields); |
| 20 |
assert.sameValue(overflowImplicit.month, 12, "default overflow is constrain"); |
| 21 |
|
| 22 |
const timeZone = "America/Vancouver"; |
| 23 |
const disambiguationEarlierFields = { timeZone, year: 2000, month: 10, day: 29, hour: 1, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 }; |
| 24 |
const disambiguationLaterFields = { timeZone, year: 2000, month: 4, day: 2, hour: 2, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 }; |
| 25 |
|
| 26 |
[ |
| 27 |
[disambiguationEarlierFields, 972808496987654321n], |
| 28 |
[disambiguationLaterFields, 954671696987654321n], |
| 29 |
].forEach(([fields, expected]) => { |
| 30 |
const explicit = Temporal.ZonedDateTime.from(fields, undefined); |
| 31 |
assert.sameValue(explicit.epochNanoseconds, expected, "default disambiguation is compatible"); |
| 32 |
|
| 33 |
const propertyImplicit = Temporal.ZonedDateTime.from(fields, {}); |
| 34 |
assert.sameValue(propertyImplicit.epochNanoseconds, expected, "default disambiguation is compatible"); |
| 35 |
|
| 36 |
const implicit = Temporal.ZonedDateTime.from(fields); |
| 37 |
assert.sameValue(implicit.epochNanoseconds, expected, "default disambiguation is compatible"); |
| 38 |
}); |
| 39 |
|
| 40 |
const offsetFields = { year: 2000, month: 5, day: 2, offset: "+23:59", timeZone: "UTC" }; |
| 41 |
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(offsetFields, undefined), "default offset is reject"); |
| 42 |
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(offsetFields, {}), "default offset is reject"); |
| 43 |
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(offsetFields), "default offset is reject"); |
| 44 |
|
| 45 |
reportCompare(0, 0); |