Bug #50475 [Asn->Fbk]: DateTime::setISODate followed by DateTime::setTime

From: Date: Mon, 24 Jan 2011 00:47:34 +0000
Subject: Bug #50475 [Asn->Fbk]: DateTime::setISODate followed by DateTime::setTime
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-158125@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=50475&edit=1

 ID:                 50475
 Updated by:         stas@php.net
 Reported by:        nandobrt at gmail dot com
 Summary:            DateTime::setISODate followed by DateTime::setTime
-Status:             Assigned
+Status:             Feedback
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows XP
 PHP Version:        5.3SVN-2009-12-15 (snap)
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Seems to work fine on a fresh checkout.


Previous Comments:
------------------------------------------------------------------------
[2010-07-18 01:29:53] k.schroeder@php.net

Automatic comment from SVN on behalf of k.schroeder
Revision: http://svn.php.net/viewvc/?view=revision&revision=301361
Log: Test for #50475

------------------------------------------------------------------------
[2010-03-19 00:55:28] Eric at Deplagne dot name

same with php 5.3.1 on debian squeeze

------------------------------------------------------------------------
[2010-01-19 13:05:37] yoarvi at gmail dot com

date_isodate_set should reset the have_relative flag once it has updated
the date/time value.

The following patch (5.3 svn tree) includes a fix and a test case for
this bug:

Index: ext/date/php_date.c
===================================================================
--- ext/date/php_date.c	(revision 293574)
+++ ext/date/php_date.c	(working copy)
@@ -3033,6 +3033,8 @@
 	
 	timelib_update_ts(dateobj->time, NULL);
 
+	dateobj->time->have_relative = 0;
+
 	RETURN_ZVAL(object, 1, 0);
 }
 /* }}} */
Index: ext/date/tests/bug50475.phpt
===================================================================
--- ext/date/tests/bug50475.phpt	(revision 0)
+++ ext/date/tests/bug50475.phpt	(revision 0)
@@ -0,0 +1,16 @@
+--TEST--
+Bug #50475 (DateTime::setISODate followed by DateTime::setTime)
+--FILE--
+<?php
+date_default_timezone_set('Asia/Calcutta');
+
+$date = new DateTime('18-01-2009 00:00:00');
+$date->setISODate(2009, 6, 1);
+echo $date->format('Y-m-d H:i:s') . "\n";
+$date->setTime(8, 0);
+echo $date->format('Y-m-d H:i:s') . "\n";
+?>
+--EXPECT--
+2009-02-02 00:00:00
+2009-02-02 08:00:00
+

------------------------------------------------------------------------
[2009-12-15 03:23:53] nandobrt at gmail dot com

Description:
------------
Calling setTime on a DateTime object after having called setISODate will
change its date.

Reproduce code:
---------------
$date = new DateTime();
$date->setISODate(2009, 6);
echo $date->format('Y-m-d H:i:s') . "<br />";
$date->setTime(8, 0);
echo $date->format('Y-m-d H:i:s');

Expected result:
----------------
2009-02-02 01:11:15
2009-02-02 08:00:00

Actual result:
--------------
2009-02-02 01:11:15
2009-03-06 08:00:00


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=50475&edit=1


Thread (6 messages)

« previous php.bugs (#158125) next »