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