php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53340 getTimestamp returns wrong values for DateTimes from DatePeriods
Submitted: 2010-11-18 10:47 UTC Modified: 2013-02-18 00:34 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: simon dot kohlmeyer at mayflower dot de Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 5.3.3 OS: Linux
Private report: No CVE-ID: None
 [2010-11-18 10:47 UTC] simon dot kohlmeyer at mayflower dot de
Description:
------------
When using a DatePeriod, calling getTimestamp on the objects returns wrong results, starting with the second Datetime.
This is probably connected with http://bugs.php.net/bug.php?id=52454 and might have been fixed by it's solution.

I'm on gentoo 64bit testing using php-5.3.3. Also confirmed on debian 32bit using php5.3.2-1.

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

$start = new Datetime('2010-11-10 08:00:00 UTC');
$delta = new DateInterval('P1D');
$snd = new Datetime('2010-11-11 08:00:00 UTC');
$period = new DatePeriod($start, $delta, 3);

echo 'We should get:   ' . $snd->getTimestamp() . "\n";

$manual = clone $start;
$manual->add($delta);
echo 'Manually adding: ' . $manual->getTimestamp() . "\n";

foreach ($period as $p) {
        // work around getTimestamp modifying date http://bugs.php.net/bug.php?id=52454
        $timestamp = $p->getTimestamp();
        echo 'From DatePeriod: ' . $timestamp . ', ';
        $tmp = new Datetime('@' . $timestamp);
        echo 'which is really: ' . $tmp->format('Y-m-d H:i:s') . ', ' . $tmp->getTimezone()->getName() . "\n";
}


Expected result:
----------------
We should get:   1289462400
Manually adding: 1289462400
From DatePeriod: 1289376000, which is really: 2010-11-10 08:00:00, +00:00
From DatePeriod: 1289462400, which is really: 2010-11-11 08:00:00, +00:00
From DatePeriod: 1289548800, which is really: 2010-11-12 08:00:00, +00:00
From DatePeriod: 1289635200, which is really: 2010-11-13 08:00:00, +00:00


Actual result:
--------------
We should get:   1289462400
Manually adding: 1289462400
From DatePeriod: 1289376000, which is really: 2010-11-10 08:00:00, +00:00
From DatePeriod: 1289548800, which is really: 2010-11-12 08:00:00, +00:00
From DatePeriod: 1289635200, which is really: 2010-11-13 08:00:00, +00:00
From DatePeriod: 1289721600, which is really: 2010-11-14 08:00:00, +00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-18 12:09 UTC] derick@php.net
-Status: Open +Status: Feedback
 [2010-11-18 12:09 UTC] derick@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/
 [2013-02-18 00:34 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: Sat Nov 23 13:01:29 2024 UTC