argument-string-date-with-utc-offset.js (1408B)
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.plainyearmonth.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 "2019-12[Africa/Abidjan]", 14 "2019-12[!Africa/Abidjan]", 15 "2019-12[u-ca=iso8601]", 16 "2019-12[Africa/Abidjan][u-ca=iso8601]", 17 "2019-12-15T00+00:00", 18 "2019-12-15T00+00:00[UTC]", 19 "2019-12-15T00+00:00[!UTC]", 20 "2019-12-15T00-02:30[America/St_Johns]", 21 ]; 22 23 for (const arg of validStrings) { 24 const result = Temporal.PlainYearMonth.from(arg); 25 26 TemporalHelpers.assertPlainYearMonth( 27 result, 28 2019, 12, "M12", 29 `"${arg}" is a valid UTC offset with time for PlainYearMonth` 30 ); 31 } 32 33 const invalidStrings = [ 34 "2022-09[u-ca=hebrew]", 35 "2022-09Z", 36 "2022-09+01:00", 37 "2022-09-15Z", 38 "2022-09-15Z[UTC]", 39 "2022-09-15Z[Europe/Vienna]", 40 "2022-09-15+00:00", 41 "2022-09-15+00:00[UTC]", 42 "2022-09-15-02:30", 43 "2022-09-15-02:30[America/St_Johns]", 44 ]; 45 46 for (const arg of invalidStrings) { 47 assert.throws( 48 RangeError, 49 () => Temporal.PlainYearMonth.from(arg), 50 `"${arg}" UTC offset without time is not valid for PlainYearMonth` 51 ); 52 } 53 54 reportCompare(0, 0);