derick                                   Sun, 07 Mar 2010 17:25:16 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=295933

Log:
- Fixed bug #49059 (DateTime::diff() repeats previous sub() operation).

Bug: http://bugs.php.net/49059 (Closed) DateTime::diff() repeats previous sub() 
operation
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/date/php_date.c
    A   php/php-src/branches/PHP_5_3/ext/date/tests/bug49059.phpt
    U   php/php-src/trunk/ext/date/php_date.c
    A   php/php-src/trunk/ext/date/tests/bug49059.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-03-07 17:23:40 UTC (rev 295932)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-03-07 17:25:16 UTC (rev 295933)
@@ -30,6 +30,8 @@
 - Fixed bug #50358 (Compile failure compiling ext/phar/util.lo). (Felipe)
 - Fixed bug #49778 (DateInterval::format("%a") is always zero when an interval
   is created from an ISO string). (Derick)
+- Fixed bug #49059 (DateTime::diff() repeats previous sub() operation).
+  (yoa...@gmail.com, Derick)


 ?? ??? 20??, PHP 5.3.2

Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/php_date.c    2010-03-07 17:23:40 UTC 
(rev 295932)
+++ php/php-src/branches/PHP_5_3/ext/date/php_date.c    2010-03-07 17:25:16 UTC 
(rev 295933)
@@ -2880,6 +2880,8 @@
        timelib_update_ts(dateobj->time, NULL);
        timelib_update_from_sse(dateobj->time);

+       dateobj->time->have_relative = 0;
+
        RETURN_ZVAL(object, 1, 0);
 }
 /* }}} */

Added: php/php-src/branches/PHP_5_3/ext/date/tests/bug49059.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/tests/bug49059.phpt                   
        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/date/tests/bug49059.phpt   2010-03-07 
17:25:16 UTC (rev 295933)
@@ -0,0 +1,34 @@
+--TEST--
+Bug #49059 (DateTime::diff() repeats previous sub() operation)
+--FILE--
+<?php
+date_default_timezone_set('Asia/Calcutta');
+
+$date1 = date_create("2009-03-27");
+$date2 = date_create("2009-03-01");
+print "\$date1 at init: " . $date1->format("Y-m-d") . "\n";
+print "\$date2 at init: " . $date2->format("Y-m-d") . "\n";
+$diff = $date1->diff($date2);
+print "\$date1 after first diff: " . $date1->format("Y-m-d") . "\n";
+print "\$diff->days after first diff: " . $diff->days . "\n";
+$date1 = $date1->sub(new DateInterval("P2D"));
+print "\$date1 after sub: " . $date1->format("Y-m-d") . "\n";
+$diff = $date1->diff($date2);
+print "\$date1 after second diff (called at \$date1): " .
+$date1->format("Y-m-d") . "\n";
+print "\$diff->days after second diff: " . $diff->days . "\n";
+$diff = $date2->diff($date1);
+print "\$date1 after third diff (called at \$date2): " .
+$date1->format("Y-m-d") . "\n";
+print "\$diff->days after third diff: " . $diff->days . "\n";
+?>
+--EXPECT--
+$date1 at init: 2009-03-27
+$date2 at init: 2009-03-01
+$date1 after first diff: 2009-03-27
+$diff->days after first diff: 26
+$date1 after sub: 2009-03-25
+$date1 after second diff (called at $date1): 2009-03-25
+$diff->days after second diff: 24
+$date1 after third diff (called at $date2): 2009-03-25
+$diff->days after third diff: 24

Modified: php/php-src/trunk/ext/date/php_date.c
===================================================================
--- php/php-src/trunk/ext/date/php_date.c       2010-03-07 17:23:40 UTC (rev 
295932)
+++ php/php-src/trunk/ext/date/php_date.c       2010-03-07 17:25:16 UTC (rev 
295933)
@@ -3009,6 +3009,8 @@
        timelib_update_ts(dateobj->time, NULL);
        timelib_update_from_sse(dateobj->time);

+       dateobj->time->have_relative = 0;
+
        RETURN_ZVAL(object, 1, 0);
 }
 /* }}} */

Added: php/php-src/trunk/ext/date/tests/bug49059.phpt
===================================================================
--- php/php-src/trunk/ext/date/tests/bug49059.phpt                              
(rev 0)
+++ php/php-src/trunk/ext/date/tests/bug49059.phpt      2010-03-07 17:25:16 UTC 
(rev 295933)
@@ -0,0 +1,34 @@
+--TEST--
+Bug #49059 (DateTime::diff() repeats previous sub() operation)
+--FILE--
+<?php
+date_default_timezone_set('Asia/Calcutta');
+
+$date1 = date_create("2009-03-27");
+$date2 = date_create("2009-03-01");
+print "\$date1 at init: " . $date1->format("Y-m-d") . "\n";
+print "\$date2 at init: " . $date2->format("Y-m-d") . "\n";
+$diff = $date1->diff($date2);
+print "\$date1 after first diff: " . $date1->format("Y-m-d") . "\n";
+print "\$diff->days after first diff: " . $diff->days . "\n";
+$date1 = $date1->sub(new DateInterval("P2D"));
+print "\$date1 after sub: " . $date1->format("Y-m-d") . "\n";
+$diff = $date1->diff($date2);
+print "\$date1 after second diff (called at \$date1): " .
+$date1->format("Y-m-d") . "\n";
+print "\$diff->days after second diff: " . $diff->days . "\n";
+$diff = $date2->diff($date1);
+print "\$date1 after third diff (called at \$date2): " .
+$date1->format("Y-m-d") . "\n";
+print "\$diff->days after third diff: " . $diff->days . "\n";
+?>
+--EXPECT--
+$date1 at init: 2009-03-27
+$date2 at init: 2009-03-01
+$date1 after first diff: 2009-03-27
+$diff->days after first diff: 26
+$date1 after sub: 2009-03-25
+$date1 after second diff (called at $date1): 2009-03-25
+$diff->days after second diff: 24
+$date1 after third diff (called at $date2): 2009-03-25
+$diff->days after third diff: 24

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to