]> granicus.if.org Git - php/commitdiff
Upgrade timelib to 2017.01
authorDerick Rethans <github@derickrethans.nl>
Sun, 12 Feb 2017 20:17:01 +0000 (20:17 +0000)
committerDerick Rethans <github@derickrethans.nl>
Sun, 12 Feb 2017 20:17:01 +0000 (20:17 +0000)
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).

NEWS
ext/date/lib/tm2unixtime.c
ext/date/lib/unixtime2tm.c
ext/date/tests/bug72719.phpt [new file with mode: 0644]
ext/date/tests/bug73294.phpt [new file with mode: 0644]
ext/date/tests/bug73489.phpt [new file with mode: 0644]
ext/date/tests/bug73858.phpt [new file with mode: 0644]
ext/date/tests/bug73942.phpt [new file with mode: 0644]
ext/date/tests/bug74057.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index cbbc383edf42566eead1650fc7a734e7e3da8d17..aed2a09e5d68334d17cb173814345073747fd2f4 100644 (file)
--- 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)
index 57e0cef1be61956874402c02799ea25a8da0d60c..83ff40b3856de5e16f45c6668f3780de22000a1e 100644 (file)
@@ -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
index a9b71662eadef9ea4e019b50f70d7f5f0b8344d0..bdef26defcbcb4b5831afddd1598920c7d0eb549 100644 (file)
@@ -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 (file)
index 0000000..634f51b
--- /dev/null
@@ -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 (file)
index 0000000..493ba92
--- /dev/null
@@ -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 (file)
index 0000000..ebb0b45
--- /dev/null
@@ -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 (file)
index 0000000..72474d3
--- /dev/null
@@ -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 (file)
index 0000000..e328ab9
--- /dev/null
@@ -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 (file)
index 0000000..35b77b6
--- /dev/null
@@ -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