tor-browser

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

time-value-maximum-range.js (1649B)


      1 // Copyright (C) 2018 Andrew Paprocki. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-date.parse
      6 description: >
      7  Date.parse return value is limited to specified time value maximum range
      8 info: |
      9  Date.parse ( string )
     10 
     11  parse interprets the resulting String as a date and time; it returns a
     12  Number, the UTC time value corresponding to the date and time.
     13 
     14  A Date object contains a Number indicating a particular instant in time to
     15  within a millisecond. Such a Number is called a time value.
     16 
     17  The actual range of times supported by ECMAScript Date objects is slightly
     18  smaller: exactly -100,000,000 days to 100,000,000 days measured relative to
     19  midnight at the beginning of 01 January, 1970 UTC. This gives a range of
     20  8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC.
     21 ---*/
     22 
     23 const minDateStr = "-271821-04-20T00:00:00.000Z";
     24 const minDate = new Date(-8640000000000000);
     25 
     26 assert.sameValue(minDate.toISOString(), minDateStr, "minDateStr");
     27 assert.sameValue(Date.parse(minDateStr), minDate.valueOf(), "parse minDateStr");
     28 
     29 const maxDateStr = "+275760-09-13T00:00:00.000Z";
     30 const maxDate = new Date(8640000000000000);
     31 
     32 assert.sameValue(maxDate.toISOString(), maxDateStr, "maxDateStr");
     33 assert.sameValue(Date.parse(maxDateStr), maxDate.valueOf(), "parse maxDateStr");
     34 
     35 const belowRange = "-271821-04-19T23:59:59.999Z";
     36 const aboveRange = "+275760-09-13T00:00:00.001Z";
     37 
     38 assert.sameValue(Date.parse(belowRange), NaN, "parse below minimum time value");
     39 assert.sameValue(Date.parse(aboveRange), NaN, "parse above maximum time value");
     40 
     41 reportCompare(0, 0);