Skip to content

Commit 7798f16

Browse files
committed
Quick fix for bug in retrieving last monday
1 parent f9ac7b6 commit 7798f16

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

functions/datetime/strtotime.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,14 @@ function strtotime (str, now) {
6161
var process = function (m) {
6262
var ago = (m[2] && m[2] === 'ago');
6363
var num = (num = m[0] === 'last' ? -1 : 1) * (ago ? -1 : 1);
64-
64+
6565
switch (m[0]) {
6666
case 'last':
6767
case 'next':
6868
switch (m[1].substring(0, 3)) {
6969
case 'yea':
7070
now.setFullYear(now.getFullYear() + num);
7171
break;
72-
case 'mon':
73-
now.setMonth(now.getMonth() + num);
74-
break;
7572
case 'wee':
7673
now.setDate(now.getDate() + (num * 7));
7774
break;
@@ -87,6 +84,12 @@ function strtotime (str, now) {
8784
case 'sec':
8885
now.setSeconds(now.getSeconds() + num);
8986
break;
87+
case 'mon':
88+
if (m[1] === "month") {
89+
now.setMonth(now.getMonth() + num);
90+
break;
91+
}
92+
// fall through
9093
default:
9194
var day = __is.day[m[1].substring(0, 3)];
9295
if (typeof day !== 'undefined') {
@@ -103,6 +106,7 @@ function strtotime (str, now) {
103106
}
104107
}
105108
now.setDate(now.getDate() + diff);
109+
now.setHours(0, 0, 0, 0); // when jumping to a specific last/previous day of week, PHP sets the time to 00:00:00
106110
}
107111
}
108112
break;

0 commit comments

Comments
 (0)