summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerick Rethans <github@derickrethans.nl>2017-02-12 20:17:01 +0000
committerDerick Rethans <github@derickrethans.nl>2017-02-12 20:17:01 +0000
commitf0519f48370d39314b3b0b64aa57fe3ac9e2a335 (patch)
tree74f6080ecaa40d1d7397e8cad7504bfceacc1ca5
parent26fdebc63b642417820017e550d46c1b1f773504 (diff)
downloadphp-git-f0519f48370d39314b3b0b64aa57fe3ac9e2a335.tar.gz
Upgrade timelib to 2017.01
This fixes: - Fixed bug #72719 (Relative datetime format ignores weekday on sundays only). - Fixed bug #73294 (DateTime wrong when date string is negative). - Fixed bug #73489 (wrong timestamp when call setTimeZone multi times with UTC offset). - Fixed bug #73858 (first/last day of' flag is not being reset). - Fixed bug #73942 ($date->modify('Friday this week') doesn't return a Friday if $date is a Sunday). - Fixed bug #74057 (wrong day when using "this week" in strtotime).
-rw-r--r--NEWS11
-rw-r--r--ext/date/lib/tm2unixtime.c6
-rw-r--r--ext/date/lib/unixtime2tm.c1
-rw-r--r--ext/date/tests/bug72719.phpt20
-rw-r--r--ext/date/tests/bug73294.phpt22
-rw-r--r--ext/date/tests/bug73489.phpt24
-rw-r--r--ext/date/tests/bug73858.phpt63
-rw-r--r--ext/date/tests/bug73942.phpt12
-rw-r--r--ext/date/tests/bug74057.phpt24
9 files changed, 180 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index cbbc383edf..aed2a09e5d 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,17 @@ PHP NEWS
. Fixed bug #61471 (Incomplete POST does not timeout but is passed to PHP).
(Zheng Shao)
+- Date:
+ . Fixed bug #72719 (Relative datetime format ignores weekday on sundays
+ only). (Derick)
+ . Fixed bug #73294 (DateTime wrong when date string is negative). (Derick)
+ . Fixed bug #73489 (wrong timestamp when call setTimeZone multi times with
+ UTC offset). (xiami, Derick)
+ . Fixed bug #73858 (first/last day of' flag is not being reset). (Derick)
+ . Fixed bug #73942 ($date->modify('Friday this week') doesn't return a Friday
+ if $date is a Sunday). (Derick)
+ . Fixed bug #74057 (wrong day when using "this week" in strtotime). (Derick)
+
- FPM:
. Fixed bug #69860 (php-fpm process accounting is broken with keepalive).
(Denis Yeldandi)
diff --git a/ext/date/lib/tm2unixtime.c b/ext/date/lib/tm2unixtime.c
index 57e0cef1be..83ff40b385 100644
--- a/ext/date/lib/tm2unixtime.c
+++ b/ext/date/lib/tm2unixtime.c
@@ -154,7 +154,7 @@ static void do_adjust_for_weekday(timelib_time* time)
{
/* To make "this week" work, where the current DOW is a "sunday" */
if (current_dow == 0 && time->relative.weekday != 0) {
- time->relative.weekday = -6;
+ time->relative.weekday -= 7;
}
/* To make "sunday this week" work, where the current DOW is not a
@@ -354,7 +354,7 @@ static timelib_sll do_years(timelib_sll year)
return res;
}
-static timelib_sll do_months(timelib_ull month, timelib_ull year)
+static timelib_sll do_months(timelib_ull month, timelib_sll year)
{
if (timelib_is_leap(year)) {
return ((month_tab_leap[month - 1] + 1) * SECS_PER_DAY);
@@ -463,7 +463,7 @@ void timelib_update_ts(timelib_time* time, timelib_tzinfo* tzi)
time->sse = res;
time->sse_uptodate = 1;
- time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = 0;
+ time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = time->relative.first_last_day_of = 0;
}
#if 0
diff --git a/ext/date/lib/unixtime2tm.c b/ext/date/lib/unixtime2tm.c
index a9b71662ea..bdef26defc 100644
--- a/ext/date/lib/unixtime2tm.c
+++ b/ext/date/lib/unixtime2tm.c
@@ -189,6 +189,7 @@ void timelib_unixtime2local(timelib_time *tm, timelib_sll ts)
timelib_unixtime2gmt(tm, ts - (tm->z * 60) + (tm->dst * 3600));
+ tm->sse = ts;
tm->z = z;
tm->dst = dst;
break;
diff --git a/ext/date/tests/bug72719.phpt b/ext/date/tests/bug72719.phpt
new file mode 100644
index 0000000000..634f51bab6
--- /dev/null
+++ b/ext/date/tests/bug72719.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #72719: Relative datetime format ignores weekday on sundays only
+--FILE--
+<?php
+echo (new DateTimeImmutable('Monday next week 13:00'))->format('l'), "\n";
+echo (new DateTimeImmutable('Tuesday next week 14:00'))->format('l'), "\n";
+echo (new DateTimeImmutable('Wednesday next week 14:00'))->format('l'), "\n";
+echo (new DateTimeImmutable('Thursday next week 15:00'))->format('l'), "\n";
+echo (new DateTimeImmutable('Friday next week 16:00'))->format('l'), "\n";
+echo (new DateTimeImmutable('Saturday next week 17:00'))->format('l'), "\n";
+echo (new DateTimeImmutable('Sunday next week 18:00'))->format('l'), "\n";
+?>
+--EXPECT--
+Monday
+Tuesday
+Wednesday
+Thursday
+Friday
+Saturday
+Sunday
diff --git a/ext/date/tests/bug73294.phpt b/ext/date/tests/bug73294.phpt
new file mode 100644
index 0000000000..493ba92dd6
--- /dev/null
+++ b/ext/date/tests/bug73294.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #73294: DateTime wrong when date string is negative
+--FILE--
+<?php
+for ( $i = -1050; $i <= -1000; $i++ )
+{
+ $M = "06";
+ $D = "22";
+
+ $dt = new DateTime("{$i}-{$M}-{$D} 00:00:00");
+ $expected = "{$i}-{$M}-{$D} 00:00:00";
+ $result = $dt->format('Y-m-d H:i:s');
+
+ if ( $expected != $result )
+ {
+ echo "Wrong: Should have been {$expected}, was {$result}\n";
+ }
+}
+?>
+==DONE==
+--EXPECT--
+==DONE==
diff --git a/ext/date/tests/bug73489.phpt b/ext/date/tests/bug73489.phpt
new file mode 100644
index 0000000000..ebb0b45b3d
--- /dev/null
+++ b/ext/date/tests/bug73489.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #73489: wrong timestamp when call setTimeZone multi times with UTC offset
+--FILE--
+<?php
+// example 1 - Timestamp is changing
+$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
+var_dump($datetime->getTimestamp());
+$datetime->setTimeZone(new DateTimeZone('-03:00'));
+$datetime->setTimeZone(new DateTimeZone('-03:00'));
+var_dump($datetime->getTimestamp());
+
+// example 2 - Timestamp keeps if you use getTimestamp() before second setTimeZone() calls
+$datetime = new DateTime('2016-11-09 20:00:00', new DateTimeZone('UTC'));
+var_dump($datetime->getTimestamp());
+$datetime->setTimeZone(new DateTimeZone('-03:00'));
+$datetime->getTimestamp();
+$datetime->setTimeZone(new DateTimeZone('-03:00'));
+var_dump($datetime->getTimestamp());
+?>
+--EXPECT--
+int(1478721600)
+int(1478721600)
+int(1478721600)
+int(1478721600)
diff --git a/ext/date/tests/bug73858.phpt b/ext/date/tests/bug73858.phpt
new file mode 100644
index 0000000000..72474d3edb
--- /dev/null
+++ b/ext/date/tests/bug73858.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Bug #73858: diff() of two relative/described DateTimes is wrong
+--FILE--
+<?php
+/*
+In the "verbose setup method" I'm trying setup the DateTime object myself
+to see if it's the format string which is parsed in correctly or if it's the DateTime
+object which is breaking stuff. From the testing it appears DateTime is broken somehow.
+*/
+$ss = 'first day of last month midnight';
+$es = 'first day of this month midnight - 1 second';
+
+$s = new DateTime($ss);
+$e = new DateTime($es);
+$d= $e->diff($s);
+var_dump($d->days); // 0 ... but should be 30
+
+$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method
+$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
+$d = $e->diff($s);
+var_dump($d->days); // 30 ... and should be 30
+
+/*
+Next we will try mix/match the code to see what happens, surprisingly it seems that the end date ($e)
+is the important one, if it uses the verbose method it returns the correct values.
+*/
+$s = (new DateTime(null))->setTimestamp(strtotime($ss)); // verbose setup method
+$e = new DateTime($es);
+$d= $e->diff($s);
+var_dump($d->days); // 0 ... but should be 30
+
+$s = new DateTime($ss);
+$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
+$d= $e->diff($s);
+var_dump($d->days); // 30 ... and should be 30
+
+/*
+This test just proves that the $e date is important BUT NOT because it's the one we call the diff() method
+on, that's just coincidental that seems to imply that the "- 1 second" in the date string is the problem.
+*/
+$s = new DateTime($ss);
+$e = (new DateTime(null))->setTimestamp(strtotime($es)); // verbose setup method
+$d= $s->diff($e);
+var_dump($d->days); // 30 ... and should be 30
+
+/*
+[Workaround]
+This final test seems to prove that the input string is important and that the "- 1 secord" has a negative knock-on
+effect on the results of the diff. By modifying the datetime with ->modify everything works as expected ...
+it just means you have to be careful of how we work with DateTimes .
+*/
+$s = new DateTime($ss);
+$e = new DateTime('first day of this month midnight');
+$e->modify('- 1 second');
+var_dump($e->diff($s)->days); // 30 ... and should be 30
+?>
+--EXPECT--
+int(30)
+int(30)
+int(30)
+int(30)
+int(30)
+int(30)
diff --git a/ext/date/tests/bug73942.phpt b/ext/date/tests/bug73942.phpt
new file mode 100644
index 0000000000..e328ab93b7
--- /dev/null
+++ b/ext/date/tests/bug73942.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Bug #73942: $date->modify('Friday this week') doesn't return a Friday if $date is a Sunday
+--FILE--
+<?php
+$date1 = "2017-01-08"; // this is a Sunday
+$date = new \DateTime($date1);
+$date->modify('Friday this week');
+$dateFormat = $date->format('Y-m-d');
+echo $dateFormat, "\n";
+?>
+--EXPECT--
+2017-01-06
diff --git a/ext/date/tests/bug74057.phpt b/ext/date/tests/bug74057.phpt
new file mode 100644
index 0000000000..35b77b600b
--- /dev/null
+++ b/ext/date/tests/bug74057.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #74057: wrong day when using "this week" in strtotime
+--FILE--
+<?php
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sun 2017-01-01")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Mon 2017-01-02")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Tue 2017-01-03")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Wed 2017-01-04")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Thu 2017-01-05")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Fri 2017-01-06")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sat 2017-01-07")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Sun 2017-01-08")))."\n";
+echo date("D Y-m-d", strtotime("saturday this week", strtotime("Mon 2017-01-09")))."\n";
+?>
+--EXPECT--
+Sat 2016-12-31
+Sat 2017-01-07
+Sat 2017-01-07
+Sat 2017-01-07
+Sat 2017-01-07
+Sat 2017-01-07
+Sat 2017-01-07
+Sat 2017-01-07
+Sat 2017-01-14