argument-string-date-with-utc-offset.js (1250B)
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.plaindatetime.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 "1976-11-18T15:23+00:00", 14 "1976-11-18T15:23+00:00[UTC]", 15 "1976-11-18T15:23+00:00[!UTC]", 16 "1976-11-18T15:23-02:30[America/St_Johns]", 17 ]; 18 19 for (const arg of validStrings) { 20 const result = Temporal.PlainDateTime.from(arg); 21 22 TemporalHelpers.assertPlainDateTime( 23 result, 24 1976, 11, "M11", 18, 15, 23, 0, 0, 0, 0, 25 `"${arg}" is a valid UTC offset with time for PlainDateTime` 26 ); 27 } 28 29 const invalidStrings = [ 30 "2022-09-15Z", 31 "2022-09-15Z[UTC]", 32 "2022-09-15Z[Europe/Vienna]", 33 "2022-09-15+00:00", 34 "2022-09-15+00:00[UTC]", 35 "2022-09-15-02:30", 36 "2022-09-15-02:30[America/St_Johns]", 37 ]; 38 39 for (const arg of invalidStrings) { 40 assert.throws( 41 RangeError, 42 () => Temporal.PlainDateTime.from(arg), 43 `"${arg}" UTC offset without time is not valid for PlainDateTime` 44 ); 45 } 46 47 reportCompare(0, 0);