#39782 [Asn]: setTime() on a DateTime constructed with a Weekday yields incorrect results

From: Date: Sat, 09 Dec 2006 15:28:44 +0000
Subject: #39782 [Asn]: setTime() on a DateTime constructed with a Weekday yields incorrect results
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-106137@lists.php.net to get a copy of this message
 ID:               39782
 Updated by:       iliaa@php.net
 Reported By:      php at michaelho dot com
 Status:           Assigned
 Bug Type:         Date/time related
 Operating System: Max OS X 10.4.7
 PHP Version:      5.2.0
 Assigned To:      derick
 New Comment:

Derick I think the patch below should take care of this 
problem
http://bb.prohost.org/patch/date.txt


Previous Comments:
------------------------------------------------------------------------

[2006-12-08 22:40:42] 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


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


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


Thread (4 messages)

« previous php.bugs (#106137) next »