tor-browser

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

parse-from-tostring-methods.js (1328B)


      1 // SKIP test262 export
      2 // Behavior is not currently specified.
      3 
      4 let dates = [
      5    "0217-09-23", "+000217-09-23", "-000217-09-23",
      6    "2017-09-23", "+002017-09-23", "-002017-09-23",
      7                  "+022017-09-23", "-022017-09-23",
      8                  "+202017-09-23", "-202017-09-23",
      9 ];
     10 
     11 for (let date of dates) {
     12    let d = new Date(date);
     13    let timeValue = d.valueOf();
     14 
     15    assertEq(Number.isNaN(timeValue), false, `Cannot parse "${date}" as ISO date-only form`);
     16 
     17    // Ensure parsing the results of toString(), toUTCString(), and toISOString()
     18    // gives the same time value as required by 20.3.3.2 Date.parse.
     19    //
     20    // Additional requirement not present in ES2019 draft rev 7acacc524213058a2368b5fa751fac7ea08ba230:
     21    // The time zone offset must not contain seconds (or milliseconds) for |Date.parse(x.toString())|
     22    // to be equal to |x.valueOf()|.
     23    let tz = d.getTimezoneOffset();
     24    if (Math.trunc(tz) === tz) {
     25        assertEq(Date.parse(d.toString()), timeValue, `Cannot parse from toString() of "${date}"`);
     26    }
     27    assertEq(Date.parse(d.toUTCString()), timeValue, `Cannot parse from toUTCString() of "${date}"`);
     28    assertEq(Date.parse(d.toISOString()), timeValue, `Cannot parse from toISOString() of "${date}"`);
     29 }
     30 
     31 if (typeof reportCompare === "function")
     32    reportCompare(true, true);