Skip to content

Commit 111a290

Browse files
committed
Merge pull request locutusjs#127 from Ivanca/patch-1
Data.parse works different in PHP & JS when truthy
2 parents 12e4271 + 9fdf994 commit 111a290

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

functions/datetime/strtotime.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
function strtotime (text, now) {
1+
2+
function strtotime(text, now) {
23
// Convert string representation of date and time to a timestamp
34
//
45
// version: 1109.2015
@@ -36,21 +37,12 @@ function strtotime (text, now) {
3637
if (text === 'now') {
3738
return now === null || isNaN(now) ? new Date().getTime() / 1000 | 0 : now | 0;
3839
}
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;
47-
}
4840

4941
match = text.match(/^(\d{2,4})-(\d{2})-(\d{2})(?:\s(\d{1,2}):(\d{2})(?::\d{2})?)?(?:\.(\d+)?)?$/);
5042
if (match) {
51-
year = match[1] >= 0 && match[1] <= 69 ? +match[1] + 2000 : match[1];
43+
year = match[1] >= 0 && match[1] <= 69 ? + match[1] + 2000 : match[1];
5244
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;
45+
match[4] || 0, match[5] || 0, match[6] || 0, match[7] || 0) / 1000 | 0;
5446
}
5547

5648
date = now ? new Date(now * 1000) : new Date();
@@ -139,5 +131,5 @@ function strtotime (text, now) {
139131
//if (!match.every(process))
140132
// return false;
141133

142-
return (date.getTime() / 1000);
134+
return (date.getTime() / 1000) | 0;
143135
}

0 commit comments

Comments
 (0)