argument-string-date-with-utc-offset.js (1473B)
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.instant.compare 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", 13 "1970-01-01T00Z[UTC]", 14 "1970-01-01T00Z[!UTC]", 15 "1970-01-01T00Z[Europe/Vienna]", 16 "1970-01-01T00+00:00", 17 "1970-01-01T00+00:00[UTC]", 18 "1970-01-01T00+00:00[!UTC]", 19 "1969-12-31T16-08:00[America/Vancouver]", 20 ]; 21 22 for (const arg of validStrings) { 23 const result = Temporal.Instant.compare(arg, arg); 24 25 assert.sameValue( 26 result, 27 0, 28 `"${arg}" is a valid UTC offset with time for Instant` 29 ); 30 } 31 32 const invalidStrings = [ 33 "2022-09-15Z", 34 "2022-09-15Z[UTC]", 35 "2022-09-15Z[Europe/Vienna]", 36 "2022-09-15+00:00", 37 "2022-09-15+00:00[UTC]", 38 "2022-09-15-02:30", 39 "2022-09-15-02:30[America/St_Johns]", 40 ]; 41 const epoch = new Temporal.Instant(0n); 42 43 for (const arg of invalidStrings) { 44 assert.throws( 45 RangeError, 46 () => Temporal.Instant.compare(arg, epoch), 47 `"${arg}" UTC offset without time is not valid for Instant (first argument)` 48 ); 49 assert.throws( 50 RangeError, 51 () => Temporal.Instant.compare(epoch, arg), 52 `"${arg}" UTC offset without time is not valid for Instant (second argument)` 53 ); 54 } 55 56 reportCompare(0, 0);