argument-string-fractional-units-rounding-mode.js (1405B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2022 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.duration.from 7 description: Strings with fractional duration units are rounded with the correct rounding mode 8 includes: [temporalHelpers.js] 9 features: [Temporal] 10 ---*/ 11 12 const resultPosHours = Temporal.Duration.from("PT1.03125H"); 13 TemporalHelpers.assertDuration(resultPosHours, 0, 0, 0, 0, 1, 1, 52, 500, 0, 0, 14 "positive fractional hours rounded with correct rounding mode"); 15 16 const resultNegHours = Temporal.Duration.from("-PT1.03125H"); 17 TemporalHelpers.assertDuration(resultNegHours, 0, 0, 0, 0, -1, -1, -52, -500, 0, 0, 18 "negative fractional hours rounded with correct rounding mode"); 19 20 // The following input should not round, but may fail if an implementation does 21 // floating point arithmetic too early: 22 23 const resultPosSeconds = Temporal.Duration.from("PT46H66M71.50040904S"); 24 TemporalHelpers.assertDuration(resultPosSeconds, 0, 0, 0, 0, 46, 66, 71, 500, 409, 40, 25 "positive fractional seconds not rounded"); 26 27 const resultNegSeconds = Temporal.Duration.from("-PT46H66M71.50040904S"); 28 TemporalHelpers.assertDuration(resultNegSeconds, 0, 0, 0, 0, -46, -66, -71, -500, -409, -40, 29 "negative fractional seconds not rounded"); 30 31 reportCompare(0, 0);