summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <github@derickrethans.nl>2016-05-18 12:19:11 +0100
committerDerick Rethans <github@derickrethans.nl>2016-05-18 12:19:11 +0100
commitf43f6fc39b92796aa934d4ae13675bb144d23435 (patch)
treee02607cee180977eb6a4a44ee2349d4a6e745c50
parent0815f7f755a6248b4b28163e09cbc1c91b15664b (diff)
downloadphp-git-f43f6fc39b92796aa934d4ae13675bb144d23435.tar.gz
Fixed bug #63740 (strtotime seems to use both sunday and monday as start of week)
-rw-r--r--NEWS2
-rw-r--r--ext/date/lib/timelib.c58
-rw-r--r--ext/date/lib/timelib.h4
-rw-r--r--ext/date/lib/tm2unixtime.c10
-rw-r--r--ext/date/tests/bug63740.phpt41
5 files changed, 83 insertions, 32 deletions
diff --git a/NEWS b/NEWS
index 3cf7aa2927..4be12a5547 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,8 @@ PHP NEWS
(Michael Sierks)
- Date:
+ . Fixed bug #63740 (strtotime seems to use both sunday and monday as start of
+ week). (Derick)
. Fixed bug #71889 (DateInterval::format Segmentation fault). (Thomas Punt)
- EXIF:
diff --git a/ext/date/lib/timelib.c b/ext/date/lib/timelib.c
index b938d9f998..b9fb66f00f 100644
--- a/ext/date/lib/timelib.c
+++ b/ext/date/lib/timelib.c
@@ -310,33 +310,33 @@ void timelib_dump_rel_time(timelib_rel_time *d)
timelib_long timelib_parse_tz_cor(char **ptr)
{
- char *begin = *ptr, *end;
- timelib_long tmp;
-
- while (isdigit(**ptr) || **ptr == ':') {
- ++*ptr;
- }
- end = *ptr;
- switch (end - begin) {
- case 1:
- case 2:
- return HOUR(strtol(begin, NULL, 10));
- break;
- case 3:
- case 4:
- if (begin[1] == ':') {
- tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);
- return tmp;
- } else if (begin[2] == ':') {
- tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
- return tmp;
- } else {
- tmp = strtol(begin, NULL, 10);
- return HOUR(tmp / 100) + tmp % 100;
- }
- case 5:
- tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
- return tmp;
- }
- return 0;
+ char *begin = *ptr, *end;
+ timelib_long tmp;
+
+ while (isdigit(**ptr) || **ptr == ':') {
+ ++*ptr;
+ }
+ end = *ptr;
+ switch (end - begin) {
+ case 1: /* H */
+ case 2: /* HH */
+ return HOUR(strtol(begin, NULL, 10));
+ break;
+ case 3: /* H:M */
+ case 4: /* H:MM, HH:M, HHMM */
+ if (begin[1] == ':') {
+ tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 2, NULL, 10);
+ return tmp;
+ } else if (begin[2] == ':') {
+ tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
+ return tmp;
+ } else {
+ tmp = strtol(begin, NULL, 10);
+ return HOUR(tmp / 100) + tmp % 100;
+ }
+ case 5: /* HH:MM */
+ tmp = HOUR(strtol(begin, NULL, 10)) + strtol(begin + 3, NULL, 10);
+ return tmp;
+ }
+ return 0;
}
diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h
index fe1069bdde..9a59d89770 100644
--- a/ext/date/lib/timelib.h
+++ b/ext/date/lib/timelib.h
@@ -38,8 +38,8 @@
# define timelib_free free
#endif
-#define TIMELIB_VERSION 201502
-#define TIMELIB_ASCII_VERSION "2015.02"
+#define TIMELIB_VERSION 201602
+#define TIMELIB_ASCII_VERSION "2016.02"
#define TIMELIB_NONE 0x00
#define TIMELIB_OVERRIDE_TIME 0x01
diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c
index 414cf13082..57e0cef1be 100644
--- a/ext/date/lib/tm2unixtime.c
+++ b/ext/date/lib/tm2unixtime.c
@@ -152,9 +152,17 @@ static void do_adjust_for_weekday(timelib_time* time)
current_dow = timelib_day_of_week(time->y, time->m, time->d);
if (time->relative.weekday_behavior == 2)
{
- if (time->relative.weekday == 0) {
+ /* To make "this week" work, where the current DOW is a "sunday" */
+ if (current_dow == 0 && time->relative.weekday != 0) {
+ time->relative.weekday = -6;
+ }
+
+ /* To make "sunday this week" work, where the current DOW is not a
+ * "sunday" */
+ if (time->relative.weekday == 0 && current_dow != 0) {
time->relative.weekday = 7;
}
+
time->d -= current_dow;
time->d += time->relative.weekday;
return;
diff --git a/ext/date/tests/bug63740.phpt b/ext/date/tests/bug63740.phpt
new file mode 100644
index 0000000000..18c5a57d77
--- /dev/null
+++ b/ext/date/tests/bug63740.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Bug #63740 (strtotime seems to use both sunday and monday as start of week)
+--FILE--
+<?php
+$dates = [
+ '2015-07-04',
+ '2015-07-05',
+ '2015-07-06',
+ '2015-07-07',
+ '2015-07-08',
+ '2015-07-09',
+ '2015-07-10',
+ '2015-07-11',
+ '2015-07-12',
+ '2015-07-13',
+ '2015-07-14',
+];
+
+foreach ( $dates as $date )
+{
+ $dt = new DateTimeImmutable( "$date 00:00 UTC" );
+
+ echo $dt->format( "D Y-m-d H:i" ), " → ";
+
+ $dtn = $dt->modify( "this week" );
+
+ echo $dtn->format( "D Y-m-d H:i" ), "\n";
+}
+?>
+--EXPECT--
+Sat 2015-07-04 00:00 → Mon 2015-06-29 00:00
+Sun 2015-07-05 00:00 → Mon 2015-06-29 00:00
+Mon 2015-07-06 00:00 → Mon 2015-07-06 00:00
+Tue 2015-07-07 00:00 → Mon 2015-07-06 00:00
+Wed 2015-07-08 00:00 → Mon 2015-07-06 00:00
+Thu 2015-07-09 00:00 → Mon 2015-07-06 00:00
+Fri 2015-07-10 00:00 → Mon 2015-07-06 00:00
+Sat 2015-07-11 00:00 → Mon 2015-07-06 00:00
+Sun 2015-07-12 00:00 → Mon 2015-07-06 00:00
+Mon 2015-07-13 00:00 → Mon 2015-07-13 00:00
+Tue 2015-07-14 00:00 → Mon 2015-07-13 00:00