| 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: Fallback value for overflow option |
| 8 |
info: | |
| 9 |
sec-getoption step 3: |
| 10 |
3. If _value_ is *undefined*, return _fallback_. |
| 11 |
sec-temporal-totemporaloverflow step 1: |
| 12 |
1. Return ? GetOption(_normalizedOptions_, *"overflow"*, « String », « *"constrain"*, *"reject"* », *"constrain"*). |
| 13 |
sec-temporal-interprettemporaldatetimefields steps 2–3: |
| 14 |
2. Let _temporalDate_ be ? DateFromFields(_calendar_, _fields_, _options_). |
| 15 |
3. Let _overflow_ be ? ToTemporalOverflow(_options_). |
| 16 |
sec-temporal-totemporalzoneddatetime steps 2–3: |
| 17 |
2. If Type(_item_) is Object, then |
| 18 |
... |
| 19 |
j. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). |
| 20 |
3. Else, |
| 21 |
a. Perform ? ToTemporalOverflow(_options_). |
| 22 |
sec-temporal.zoneddatetime.from steps 2–3: |
| 23 |
2. If Type(_item_) is Object and _item_ has an [[InitializedTemporalZonedDateTime]] internal slot, then |
| 24 |
a. Perform ? ToTemporalOverflow(_options_). |
| 25 |
... |
| 26 |
d. Return ... |
| 27 |
3. Return ? ToTemporalZonedDateTime(_item_, _options_). |
| 28 |
features: [Temporal] |
| 29 |
---*/ |
| 30 |
|
| 31 |
const validValues = [ |
| 32 |
new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC"), |
| 33 |
"2001-09-09T01:46:40.987654321+00:00[UTC]", |
| 34 |
]; |
| 35 |
validValues.forEach((value) => { |
| 36 |
const explicit = Temporal.ZonedDateTime.from(value, { overflow: undefined }); |
| 37 |
assert.sameValue(explicit.epochNanoseconds, 1_000_000_000_987_654_321n, "overflow is ignored"); |
| 38 |
const implicit = Temporal.ZonedDateTime.from(value, {}); |
| 39 |
assert.sameValue(implicit.epochNanoseconds, 1_000_000_000_987_654_321n, "overflow is ignored"); |
| 40 |
}); |
| 41 |
|
| 42 |
const propertyBag = { year: 2000, month: 15, day: 34, hour: 12, timeZone: "UTC" }; |
| 43 |
const explicit = Temporal.ZonedDateTime.from(propertyBag, { overflow: undefined }); |
| 44 |
assert.sameValue(explicit.epochNanoseconds, 978_264_000_000_000_000n, "default overflow is constrain"); |
| 45 |
|
| 46 |
// See options-undefined for {} |
| 47 |
|
| 48 |
reportCompare(0, 0); |