]> granicus.if.org Git - php/commitdiff
- Fixed a bug in DateTime->modify() where absolute date/time statements had no
authorDerick Rethans <derick@php.net>
Wed, 15 Dec 2010 21:45:25 +0000 (21:45 +0000)
committerDerick Rethans <derick@php.net>
Wed, 15 Dec 2010 21:45:25 +0000 (21:45 +0000)
  effect.

NEWS
ext/date/php_date.c
ext/date/tests/DateTime_modify_variation1.phpt
ext/date/tests/date-time-modify-times.phpt [new file with mode: 0644]
ext/date/tests/date_modify_variation2.phpt

diff --git a/NEWS b/NEWS
index c38ccd0d81cdd4ddba0b85143d3ae44cd4ca07e3..4c67881f45c7fe8886894fba14c8939404065033 100644 (file)
--- a/NEWS
+++ b/NEWS
   . Fixed bug #48607 (fwrite() doesn't check reply from ftp server before
     exiting). (Ilia)
   
+- DateTime extension:
+  . Fixed a bug in DateTime->modify() where absolute date/time statements had
+    no effect. (Derick)
+
 - Filter extension:
   . Fixed bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges).
     (Ilia)
index 568ba5a99e825c3d37e84ef3f9a84f0c82797f32..57d721bc19dd4a85ea869003073cf77fb89ca61e 100644 (file)
@@ -2797,6 +2797,31 @@ PHP_FUNCTION(date_modify)
        memcpy(&dateobj->time->relative, &tmp_time->relative, sizeof(struct timelib_rel_time));
        dateobj->time->have_relative = tmp_time->have_relative;
        dateobj->time->sse_uptodate = 0;
+
+       if (tmp_time->y != -99999) {
+               dateobj->time->y = tmp_time->y;
+       }
+       if (tmp_time->m != -99999) {
+               dateobj->time->m = tmp_time->m;
+       }
+       if (tmp_time->d != -99999) {
+               dateobj->time->d = tmp_time->d;
+       }
+
+       if (tmp_time->h != -99999) {
+               dateobj->time->h = tmp_time->h;
+               if (tmp_time->i != -99999) {
+                       dateobj->time->i = tmp_time->i;
+                       if (tmp_time->s != -99999) {
+                               dateobj->time->s = tmp_time->s;
+                       } else {
+                               dateobj->time->s = 0;
+                       }
+               } else {
+                       dateobj->time->i = 0;
+                       dateobj->time->s = 0;
+               }
+       }
        timelib_time_dtor(tmp_time);
 
        timelib_update_ts(dateobj->time, NULL);
index 4d27071d04a88e2c8eefd3d0470b734df4068ca1..faeb70cbd9f213f9f9c7f1ebf1694482b5e06667 100644 (file)
@@ -133,7 +133,7 @@ bool(false)
 -- float 10.5 --
 object(DateTime)#3 (3) {
   ["date"]=>
-  string(19) "2009-01-31 14:28:41"
+  string(19) "2009-01-31 10:05:00"
   ["timezone_type"]=>
   int(3)
   ["timezone"]=>
@@ -148,7 +148,7 @@ bool(false)
 -- float .5 --
 object(DateTime)#3 (3) {
   ["date"]=>
-  string(19) "2009-01-31 14:28:41"
+  string(19) "2009-01-31 00:05:00"
   ["timezone_type"]=>
   int(3)
   ["timezone"]=>
diff --git a/ext/date/tests/date-time-modify-times.phpt b/ext/date/tests/date-time-modify-times.phpt
new file mode 100644 (file)
index 0000000..258ddbd
--- /dev/null
@@ -0,0 +1,47 @@
+--TEST--
+Test for DateTime::modify() with absolute time statements
+--INI--
+date.timezone=Europe/London
+--FILE--
+<?php
+$tests = array(
+       '2010-12-15 19:42:45 UTC' => array(
+               'october 23:00', // October 23rd, with a broken time
+               'back of 4pm',
+               'next week monday',
+               'next week monday 10am',
+               'tuesday noon',
+               'first monday of January 2011',
+               'first monday of January 2011 09:00',
+       ),
+       '2010-12-15 19:42:45' => array(
+               'october 23:00', // October 23rd, with a broken time
+               'march 28, 00:15',
+               'march 28, 01:15', // doesn't exist bcause of DST
+               'march 28, 02:15',
+       ),
+);
+
+foreach ( $tests as $start => $data )
+{
+       foreach ( $data as $test )
+       {
+               echo date_create( $start )
+                       ->modify( $test )
+                       ->format( DateTime::RFC2822 ), "\n";
+       }
+}
+echo "\n";
+?>
+--EXPECT--
+Sat, 23 Oct 2010 00:00:00 +0000
+Wed, 15 Dec 2010 16:15:00 +0000
+Mon, 20 Dec 2010 00:00:00 +0000
+Mon, 20 Dec 2010 10:00:00 +0000
+Tue, 21 Dec 2010 12:00:00 +0000
+Mon, 03 Jan 2011 00:00:00 +0000
+Mon, 03 Jan 2011 09:00:00 +0000
+Sat, 23 Oct 2010 00:00:00 +0100
+Sun, 28 Mar 2010 00:15:00 +0000
+Sun, 28 Mar 2010 02:15:00 +0100
+Sun, 28 Mar 2010 02:15:00 +0100
index 08db14cf892c3426d0c0b81cfd9f12da12d5da3a..fe6afb16dde4fa72cbfd1405a5de30c26ef00b77 100644 (file)
@@ -133,7 +133,7 @@ bool(false)
 -- float 10.5 --
 object(DateTime)#%d (3) {
   ["date"]=>
-  string(19) "2009-01-31 14:28:41"
+  string(19) "2009-01-31 10:05:00"
   ["timezone_type"]=>
   int(3)
   ["timezone"]=>
@@ -148,7 +148,7 @@ bool(false)
 -- float .5 --
 object(DateTime)#%d (3) {
   ["date"]=>
-  string(19) "2009-01-31 14:28:41"
+  string(19) "2009-01-31 00:05:00"
   ["timezone_type"]=>
   int(3)
   ["timezone"]=>