| 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: Negative time fields are balanced upwards if the argument is given as ZonedDateTime |
| 8 |
info: | |
| 9 |
sec-temporal-balancetime steps 3–14: |
| 10 |
3. Set _microsecond_ to _microsecond_ + floor(_nanosecond_ / 1000). |
| 11 |
4. Set _nanosecond_ to _nanosecond_ modulo 1000. |
| 12 |
5. Set _millisecond_ to _millisecond_ + floor(_microsecond_ / 1000). |
| 13 |
6. Set _microsecond_ to _microsecond_ modulo 1000. |
| 14 |
7. Set _second_ to _second_ + floor(_millisecond_ / 1000). |
| 15 |
8. Set _millisecond_ to _millisecond_ modulo 1000. |
| 16 |
9. Set _minute_ to _minute_ + floor(_second_ / 60). |
| 17 |
10. Set _second_ to _second_ modulo 60. |
| 18 |
11. Set _hour_ to _hour_ + floor(_minute_ / 60). |
| 19 |
12. Set _minute_ to _minute_ modulo 60. |
| 20 |
13. Let _days_ be floor(_hour_ / 24). |
| 21 |
14. Set _hour_ to _hour_ modulo 24. |
| 22 |
sec-temporal-balanceisodatetime step 1: |
| 23 |
1. Let _balancedTime_ be ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_). |
| 24 |
sec-temporal-builtintimezonegetplaindatetimefor step 3: |
| 25 |
3. Set _result_ to ? BalanceISODateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]] + _offsetNanoseconds_). |
| 26 |
sec-temporal-totemporaldatetime step 3.b: |
| 27 |
b. If _item_ has an [[InitializedTemporalZonedDateTime]] internal slot, then |
| 28 |
... |
| 29 |
ii. 1. Return ? BuiltinTimeZoneGetPlainDateTimeFor(_item_.[[TimeZone]], _instant_, _item_.[[Calendar]]). |
| 30 |
sec-temporal.plaindatetime.from step 3: |
| 31 |
3. Return ? ToTemporalDateTime(_temporalTime_). |
| 32 |
includes: [temporalHelpers.js] |
| 33 |
features: [Temporal] |
| 34 |
---*/ |
| 35 |
|
| 36 |
// This code path is encountered if the time zone offset is negative and its |
| 37 |
// absolute value in nanoseconds is greater than the nanosecond field of the |
| 38 |
// exact time's epoch parts |
| 39 |
const datetime = new Temporal.ZonedDateTime(3661_001_001_001n, "-00:02"); |
| 40 |
|
| 41 |
const pdt = Temporal.PlainDateTime.from(datetime); |
| 42 |
|
| 43 |
TemporalHelpers.assertPlainDateTime(pdt, 1970, 1, "M01", 1, 0, 59, 1, 1, 1, 1); |
| 44 |
|
| 45 |
reportCompare(0, 0); |