php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50475 DateTime::setISODate followed by DateTime::setTime
Submitted: 2009-12-15 03:23 UTC Modified: 2013-02-18 00:33 UTC
Votes:11
Avg. Score:4.3 ± 0.9
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:2 (18.2%)
From: nandobrt at gmail dot com Assigned: derick (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.3SVN-2009-12-15 (snap) OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nandobrt at gmail dot com
New email:
PHP Version: OS:

 

 [2009-12-15 03:23 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-19 13:05 UTC] 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
+
 [2010-03-19 00:55 UTC] Eric at Deplagne dot name
same with php 5.3.1 on debian squeeze
 [2010-03-19 00:57 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2010-07-18 01:29 UTC] k.schroeder@php.net
Automatic comment from SVN on behalf of k.schroeder
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=301361
Log: Test for #50475
 [2011-01-24 01:47 UTC] stas@php.net
-Status: Assigned +Status: Feedback
 [2011-01-24 01:47 UTC] stas@php.net
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.
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC