argument-string-date-with-utc-offset.js (1087B)
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.zoneddatetime.from 7 description: UTC offset not valid with format that does not include a time 8 features: [Temporal] 9 ---*/ 10 11 const validStrings = [ 12 "1970-01-01T00Z[UTC]", 13 "1970-01-01T00Z[!UTC]", 14 "1970-01-01T00+00:00[UTC]", 15 "1970-01-01T00+00:00[!UTC]", 16 ]; 17 18 for (const arg of validStrings) { 19 const result = Temporal.ZonedDateTime.from(arg); 20 21 assert.sameValue( 22 result.timeZoneId, 23 "UTC", 24 `"${arg}" is a valid UTC offset with time for ZonedDateTime` 25 ); 26 } 27 28 const invalidStrings = [ 29 "2022-09-15Z[UTC]", 30 "2022-09-15Z[Europe/Vienna]", 31 "2022-09-15+00:00[UTC]", 32 "2022-09-15-02:30[America/St_Johns]", 33 ]; 34 35 for (const arg of invalidStrings) { 36 assert.throws( 37 RangeError, 38 () => Temporal.ZonedDateTime.from(arg), 39 `"${arg}" UTC offset without time is not valid for ZonedDateTime` 40 ); 41 } 42 43 reportCompare(0, 0);