argument-string-date-with-utc-offset.js (1413B)
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.plaintime.from 7 description: UTC offset not valid with format that does not include a time 8 features: [Temporal] 9 includes: [temporalHelpers.js] 10 ---*/ 11 12 const validStrings = [ 13 "12:34:56.987654321+00:00", 14 "12:34:56.987654321+00:00[UTC]", 15 "12:34:56.987654321+00:00[!UTC]", 16 "12:34:56.987654321-02:30[America/St_Johns]", 17 "1976-11-18T12:34:56.987654321+00:00", 18 "1976-11-18T12:34:56.987654321+00:00[UTC]", 19 "1976-11-18T12:34:56.987654321+00:00[!UTC]", 20 "1976-11-18T12:34:56.987654321-02:30[America/St_Johns]", 21 ]; 22 23 for (const arg of validStrings) { 24 const result = Temporal.PlainTime.from(arg); 25 26 TemporalHelpers.assertPlainTime( 27 result, 28 12, 34, 56, 987, 654, 321, 29 `"${arg}" is a valid UTC offset with time for PlainTime` 30 ); 31 } 32 33 const invalidStrings = [ 34 "2022-09-15Z", 35 "2022-09-15Z[UTC]", 36 "2022-09-15Z[Europe/Vienna]", 37 "2022-09-15+00:00", 38 "2022-09-15+00:00[UTC]", 39 "2022-09-15-02:30", 40 "2022-09-15-02:30[America/St_Johns]", 41 ]; 42 43 for (const arg of invalidStrings) { 44 assert.throws( 45 RangeError, 46 () => Temporal.PlainTime.from(arg), 47 `"${arg}" UTC offset without time is not valid for PlainTime` 48 ); 49 } 50 51 reportCompare(0, 0);