Bug #63863 [Com]: DateTime:setDate() date not used after modify("last day of...")

From: Date: Wed, 25 Jun 2014 11:01:35 +0000
Subject: Bug #63863 [Com]: DateTime:setDate() date not used after modify("last day of...")
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186337@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63863&edit=1

 ID:                 63863
 Comment by:         gsdev at me dot com
 Reported by:        brian dot feaver at sellingsource dot com
 Summary:            DateTime:setDate() date not used after modify("last
                     day of...")
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Mac OS X
 PHP Version:        5.3.20
 Block user comment: N
 Private report:     N

 New Comment:

Hi,

This is happening on Mac OS X 10.8.5

PHP 5.5.0 (cli) (built: Jun 21 2013 12:09:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0-dev, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans

It looks to be working in PHP 5.2 but broke in PHP 5.3 onwards.

http://3v4l.org/H3jZY

<?php


		date_default_timezone_set('UTC');
 
		$date = new DateTime(null, new DateTimeZone('UTC'));
		$date->setTime(0,0,0);
		$date->modify('next month');
		$date->modify('last day of this month');
		$date->setDate(2014, 1, 21);

		// This should be 21st Jan 2014
		echo $date->format('Y-m-d');


Previous Comments:
------------------------------------------------------------------------
[2014-01-14 09:45:12] ieskok at ramuno dot lt

Confirmed in 5.5.7 & 5.5.8 on Ubuntu 12.04 x64

------------------------------------------------------------------------
[2013-11-27 17:29:56] derick@php.net

Not quite sure whether this patch is correct, but I'll check it out!

------------------------------------------------------------------------
[2013-09-20 01:13:21] php at seven dot net dot nz

Confirmed still a bug in 5.5.4 on Mac OS X.

------------------------------------------------------------------------
[2013-08-02 00:38:48] f21 dot groups at gmail dot com

I am also seeing this in PHP 5.5.1 on Ubuntu 13.04 x64.

------------------------------------------------------------------------
[2013-04-04 17:03:08] armin at fruux dot com

Besides from being able to reproduce this completely, it also happens
when using setTimestamp(), as the day keeps being 'last day of month'.

PHP version: 5.4.9
OS: Mac OS X


Test script:
------------
<?php

$date = new DateTime('2012-03-30');

$date->modify("last day of last month");
var_dump($date->format('Y-m-d')); // correctly last day of Feb

$date->setTimestamp(1327881600); // 2012-01-30
var_dump($date->format('Y-m-d')); // incorrect date

$date->modify('2012-01-30');
var_dump($date->format('Y-m-d')); // does set correct date

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=63863


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


Thread (15 messages)

« previous php.bugs (#186337) next »