tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

relativeto-sub-minute-offset.js (2251B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2021 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.duration.compare
      7 description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes
      8 features: [Temporal]
      9 ---*/
     10 
     11 let duration1 = new Temporal.Duration(0, 0, 0, 31);
     12 let duration2 = new Temporal.Duration(0, 1);
     13 
     14 let result;
     15 let relativeTo;
     16 
     17 const action = (relativeTo) => Temporal.Duration.compare(duration1, duration2, { relativeTo });
     18 
     19 relativeTo = "1970-01-01T00:00:00-00:45[Africa/Monrovia]";
     20 result = action(relativeTo);
     21 assert.sameValue(result, 0, "rounded HH:MM is accepted in string offset");
     22 
     23 relativeTo = "1970-01-01T00:00:00-00:44:30[Africa/Monrovia]";
     24 result = action(relativeTo);
     25 assert.sameValue(result, 0, "unrounded HH:MM:SS is accepted in string offset");
     26 
     27 relativeTo = "1970-01-01T00:00:00-00:44:40[Africa/Monrovia]";
     28 assert.throws(RangeError, () => action(relativeTo), "wrong :SS not accepted in string offset");
     29 
     30 relativeTo = "1970-01-01T00:00:00-00:45:00[Africa/Monrovia]";
     31 assert.throws(RangeError, () => action(relativeTo), "rounded HH:MM:SS not accepted in string offset");
     32 
     33 relativeTo = { year: 1970, month: 1, day: 1, offset: "-00:45", timeZone: "Africa/Monrovia" };
     34 assert.throws(RangeError, () => action(relativeTo), "rounded HH:MM not accepted as offset in property bag");
     35 
     36 // Pacific/Niue edge case
     37 
     38 duration1 = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 24);
     39 duration2 = new Temporal.Duration(0, 0, 0, /* days = */ 1);
     40 
     41 assert.sameValue(
     42  action("1952-10-15T23:59:59-11:19:40[Pacific/Niue]"), -1,
     43  "-11:19:40 is accepted as -11:19:40 in Pacific/Niue edge case"
     44 );
     45 assert.sameValue(
     46  action("1952-10-15T23:59:59-11:20[Pacific/Niue]"), -1,
     47  "-11:20 matches the first candidate -11:19:40 in the Pacific/Niue edge case"
     48 );
     49 assert.sameValue(
     50  action("1952-10-15T23:59:59-11:20:00[Pacific/Niue]"), 0,
     51  "-11:20:00 is accepted as -11:20:00 in the Pacific/Niue edge case"
     52 );
     53 assert.throws(
     54  RangeError, () => action("1952-10-15T23:59:59-11:19:50[Pacific/Niue]"),
     55  "wrong :SS not accepted in the Pacific/Niue edge case"
     56 );
     57 
     58 reportCompare(0, 0);