|
1 |
| -function strtotime (text, now) { |
| 1 | + |
| 2 | + |
| 3 | +function strtotime(text, now) { |
2 | 4 | // Convert string representation of date and time to a timestamp
|
3 | 5 | //
|
4 | 6 | // version: 1109.2015
|
@@ -34,23 +36,16 @@ function strtotime (text, now) {
|
34 | 36 | .toLowerCase();
|
35 | 37 |
|
36 | 38 | if (text === 'now') {
|
37 |
| - return now === null || isNaN(now) ? new Date().getTime() / 1000 | 0 : now | 0; |
38 |
| - } |
39 |
| - if (!isNaN(parsed = Date.parse(text))) { |
40 |
| - return parsed / 1000 | 0; |
41 |
| - } |
42 |
| - if (text === 'now') { |
43 |
| - return new Date().getTime() / 1000; // Return seconds, not milli-seconds |
44 |
| - } |
45 |
| - if (!isNaN(parsed = Date.parse(text))) { |
46 |
| - return parsed / 1000; |
| 39 | + return now === null || isNaN(now) ? |
| 40 | + new Date().getTime() / 1000 | 0 : |
| 41 | + now | 0; |
47 | 42 | }
|
48 | 43 |
|
49 | 44 | match = text.match(/^(\d{2,4})-(\d{2})-(\d{2})(?:\s(\d{1,2}):(\d{2})(?::\d{2})?)?(?:\.(\d+)?)?$/);
|
50 | 45 | if (match) {
|
51 |
| - year = match[1] >= 0 && match[1] <= 69 ? +match[1] + 2000 : match[1]; |
| 46 | + year = match[1] >= 0 && match[1] <= 69 ? + match[1] + 2000 : match[1]; |
52 | 47 | return new Date(year, parseInt(match[2], 10) - 1, match[3],
|
53 |
| - match[4] || 0, match[5] || 0, match[6] || 0, match[7] || 0) / 1000; |
| 48 | + match[4] || 0, match[5] || 0, match[6] || 0, match[7] || 0) / 1000 | 0; |
54 | 49 | }
|
55 | 50 |
|
56 | 51 | date = now ? new Date(now * 1000) : new Date();
|
@@ -139,5 +134,5 @@ function strtotime (text, now) {
|
139 | 134 | //if (!match.every(process))
|
140 | 135 | // return false;
|
141 | 136 |
|
142 |
| - return (date.getTime() / 1000); |
| 137 | + return (date.getTime() / 1000) | 0; |
143 | 138 | }
|
0 commit comments