| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d6ae50f commit d461603
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # Reset this number to 0 on major V8 upgrades. | |
| 38 | 38 | # Increment by one for each non-official patch applied to deps/v8. | |
| 39 | - 'v8_embedder_string': '-node.11', | ||
| 39 | + 'v8_embedder_string': '-node.12', | ||
| 40 | 40 | ||
| 41 | 41 | ##### V8 defaults for Node.js ##### | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,6 +75,9 @@ class DateParser : public AllStatic { | |||
| 75 | 75 | int ReadUnsignedNumeral() { | |
| 76 | 76 | int n = 0; | |
| 77 | 77 | int i = 0; | |
| 78 | + // First, skip leading zeros | ||
| 79 | + while (ch_ == '0') Next(); | ||
| 80 | + // And then, do the conversion | ||
| 78 | 81 | while (IsAsciiDigit()) { | |
| 79 | 82 | if (i < kMaxSignificantDigits) n = n * 10 + ch_ - '0'; | |
| 80 | 83 | i++; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,54 @@ | |||
| 1 | + // Copyright 2021 the V8 project authors. All rights reserved. | ||
| 2 | + // Use of this source code is governed by a BSD-style license that can be | ||
| 3 | + // found in the LICENSE file. | ||
| 4 | + | ||
| 5 | + const dates = [{ year: '2021', month: '10', day: '22', hour: '10', minute: '12', second: '32' }, | ||
| 6 | + { year: '2021', month: '8', day: '3', hour: '9', minute: '9', second: '6' }]; | ||
| 7 | + | ||
| 8 | + for (let date of dates) { | ||
| 9 | + const { year, month, day, hour, minute, second } = date; | ||
| 10 | + const s0 = `${year}-${month}-${day} ${hour}:${minute}:${second}Z`; | ||
| 11 | + | ||
| 12 | + // V8 reads at most kMaxSignificantDigits (9) to build the value of a numeral, | ||
| 13 | + // so let's test up to 9 leading zeros. | ||
| 14 | + | ||
| 15 | + // For years | ||
| 16 | + for (let i = 1; i < 10; i++) { | ||
| 17 | + const s1 = `${'0'.repeat(i) + year}-${month}-${day} ${hour}:${minute}:${second}Z`; | ||
| 18 | + assertTrue(new Date(s0).getTime() == new Date(s1).getTime()); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + // For months | ||
| 22 | + for (let i = 1; i < 10; i++) { | ||
| 23 | + const s1 = `${year}-${'0'.repeat(i) + month}-${day} ${hour}:${minute}:${second}Z`; | ||
| 24 | + assertTrue(new Date(s0).getTime() == new Date(s1).getTime()); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + // For days | ||
| 28 | + for (let i = 1; i < 10; i++) { | ||
| 29 | + const s1 = `${year}-${month}-${'0'.repeat(i) + day} ${hour}:${minute}:${second}Z`; | ||
| 30 | + assertTrue(new Date(s0).getTime() == new Date(s1).getTime()); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + // For hours | ||
| 34 | + for (let i = 1; i < 10; i++) { | ||
| 35 | + const s1 = `${year}-${month}-${day} ${'0'.repeat(i) + hour}:${minute}:${second}Z`; | ||
| 36 | + assertTrue(new Date(s0).getTime() == new Date(s1).getTime()); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + // For minutes | ||
| 40 | + for (let i = 1; i < 10; i++) { | ||
| 41 | + const s1 = `${year}-${month}-${day} ${hour}:${'0'.repeat(i) + minute}:${second}Z`; | ||
| 42 | + assertTrue(new Date(s0).getTime() == new Date(s1).getTime()); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + // For seconds | ||
| 46 | + for (let i = 1; i < 10; i++) { | ||
| 47 | + const s1 = `${year}-${month}-${day} ${hour}:${minute}:${'0'.repeat(i) + second}Z`; | ||
| 48 | + assertTrue(new Date(s0).getTime() == new Date(s1).getTime()); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + // With same input date string, | ||
| 52 | + // Date() and Date.parse() should return the same date | ||
| 53 | + assertTrue(new Date(s0).getTime() == Date.parse(s0)); | ||
| 54 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments