| 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.plaindatetime.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-totemporaldatetime steps 2–3: |
| 17 |
2. If Type(_item_) is Object, then |
| 18 |
... |
| 19 |
g. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). |
| 20 |
3. Else, |
| 21 |
a. Perform ? ToTemporalOverflow(_options_). |
| 22 |
sec-temporal.plaindatetime.from steps 2–3: |
| 23 |
2. If Type(_item_) is Object and _item_ has an [[InitializedTemporalDateTime]] internal slot, then |
| 24 |
a. Perform ? ToTemporalOverflow(_options_). |
| 25 |
b. Return ... |
| 26 |
3. Return ? ToTemporalDateTime(_item_, _options_). |
| 27 |
includes: [temporalHelpers.js] |
| 28 |
features: [Temporal] |
| 29 |
---*/ |
| 30 |
|
| 31 |
const validValues = [ |
| 32 |
new Temporal.PlainDateTime(2000, 5, 2, 12), |
| 33 |
"2000-05-02T12:00", |
| 34 |
]; |
| 35 |
validValues.forEach((value) => { |
| 36 |
const explicit = Temporal.PlainDateTime.from(value, { overflow: undefined }); |
| 37 |
TemporalHelpers.assertPlainDateTime(explicit, 2000, 5, "M05", 2, 12, 0, 0, 0, 0, 0, "overflow is ignored"); |
| 38 |
const implicit = Temporal.PlainDateTime.from(value, {}); |
| 39 |
TemporalHelpers.assertPlainDateTime(implicit, 2000, 5, "M05", 2, 12, 0, 0, 0, 0, 0, "overflow is ignored"); |
| 40 |
}); |
| 41 |
|
| 42 |
const propertyBag = { year: 2000, month: 13, day: 34, hour: 12 }; |
| 43 |
const explicit = Temporal.PlainDateTime.from(propertyBag, { overflow: undefined }); |
| 44 |
TemporalHelpers.assertPlainDateTime(explicit, 2000, 12, "M12", 31, 12, 0, 0, 0, 0, 0, "default overflow is constrain"); |
| 45 |
const implicit = Temporal.PlainDateTime.from(propertyBag, {}); |
| 46 |
TemporalHelpers.assertPlainDateTime(implicit, 2000, 12, "M12", 31, 12, 0, 0, 0, 0, 0, "default overflow is constrain"); |
| 47 |
|
| 48 |
reportCompare(0, 0); |