Bug #67634 [Opn->Csd]: getTimestamp() modify instance of DateTimeImmutable

From: Date: Wed, 23 Oct 2019 13:34:55 +0000
Subject: Bug #67634 [Opn->Csd]: getTimestamp() modify instance of DateTimeImmutable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223415@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67634&edit=1

 ID:                 67634
 Updated by:         cmb@php.net
 Reported by:        mathieu at rochette dot cc
 Summary:            getTimestamp() modify instance of DateTimeImmutable
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Date/time related
 Operating System:   ubuntu
 PHP Version:        5.5.14
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

This bug is already been fixed as of PHP 7.0.4, see <https://3v4l.org/M5Hcu>.


Previous Comments:
------------------------------------------------------------------------
[2019-10-06 22:15:02] aleh dot kashnikau at gmail dot com

Bug is still present in 7 version: https://3v4l.org/uk3fZ

------------------------------------------------------------------------
[2014-10-16 19:19:41] sjon at hortensius dot net

This bug is present in all php-versions including php7:

http://3v4l.org/M5Hcu

The bug can also be simplified to http://3v4l.org/ShFpG; where
it shows that the ->modify() call is irrelevant

------------------------------------------------------------------------
[2014-07-16 15:28:40] mathieu at rochette dot cc

Description:
------------
calling getTimestamp() on an instance of a DateTimeImmutable modify it (and return the modified date
timestamp).

calling format('U') does not modify the date

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

$date = new DateTimeImmutable('2014-05');

$date2 = $date->modify('first day of next month midnight - 1 second');

var_dump($date2->format('c'));
var_dump($date2->format('U'));
var_dump($date2->format('c'));
var_dump($date2->getTimestamp());
var_dump($date2->format('U'));
var_dump($date2->format('c'));


Expected result:
----------------
string(25) "2014-05-31T23:59:59+00:00"
string(10) "1401580799"
string(25) "2014-05-31T23:59:59+00:00"
int(1401580799)
string(10) "1401580799"
string(25) "2014-05-31T23:59:59+00:00"


Actual result:
--------------
string(25) "2014-05-31T23:59:59+00:00"
string(10) "1401580799"
string(25) "2014-05-31T23:59:59+00:00"
int(1398988799)
string(10) "1398988799"
string(25) "2014-05-01T23:59:59+00:00"


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



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


Thread (4 messages)

« previous php.bugs (#223415) next »