php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39782 setTime() on a DateTime constructed with a Weekday yields incorrect results
Submitted: 2006-12-08 22:40 UTC Modified: 2006-12-11 21:09 UTC
From: php at michaelho dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 5.2.0 OS: Max OS X 10.4.7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at michaelho dot com
New email:
PHP Version: OS:

 

 [2006-12-08 22:40 UTC] php at michaelho dot com
Description:
------------
When calling setTime() on a DateTime that has been constructed with a Weekday (e.g. new DateTime('Wednesday'))...

Calling setTime() causes the date to "jump" to the Next Sunday.  This happens on each and every call to setTime().

Reproduce code:
---------------
<?php
	$dttTest = new DateTime('Next Wednesday');
	print $dttTest->format('D M j Y - H:i:s') . '<br/>';
	/* Correctly outputs: "Wed Dec 13 2006 - 00:00:00" */

	$dttTest->setTime(12, 0, 0);
	print $dttTest->format('D M j Y - H:i:s') . '<br/>';
	/* EXPECTING: "Wed Dec 13 2006 - 12:00:00" */
	/* ACTUAL: "Sun Dec 17 2006 - 12:00:00" */

	$dttTest->setTime(12, 0, 0);
	print $dttTest->format('D M j Y - H:i:s') . '<br/>';
	/* EXPECTING: "Wed Dec 13 2006 - 12:00:00" */
	/* ACTUAL: "Sun Dec 24 2006 - 12:00:00" */
?>

Expected result:
----------------
Wed Dec 13 2006 - 00:00:00
Wed Dec 13 2006 - 12:00:00
Wed Dec 13 2006 - 12:00:00


Actual result:
--------------
Wed Dec 13 2006 - 00:00:00
Sun Dec 17 2006 - 12:00:00
Sun Dec 24 2006 - 12:00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-09 15:28 UTC] iliaa@php.net
Derick I think the patch below should take care of this 
problem
http://bb.prohost.org/patch/date.txt
 [2006-12-11 21:09 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC