php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69912 MongoDate->toDatetime() timezone
Submitted: 2015-06-23 13:46 UTC Modified: 2015-06-23 13:53 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: eric at ericgrysko dot com Assigned:
Status: Open Package: mongo (PECL)
PHP Version: 5.5.26 OS: RHEL 6
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-06-23 13:46 UTC] eric at ericgrysko dot com
Description:
------------
After creating a MongoDate() using a date prior to the negative 32bit unix epoch (before Dec 13 1901), unexpected results unless specifically call setTimezone() on the resulting DateTime() object.

Behavior began in PHP-5.5.25 and confirmed in PHP-5.5.26, confirms as expected in PHP-5.5.24.

Test script:
---------------
date_default_timezone_set('America/New_York');

$dateString = '1900-01-01 12:20:00';

$dateTime = new \DateTime($dateString);
var_dump($dateTime);

$mongoDateTime = new MongoDate(strtotime($dateString));

$dateTimeTest = $mongoDateTime->toDateTime();
var_dump($dateTimeTest);

// to get expected result
$dateTimeTest->setTimezone(new DateTimeZone('America/New_York'));  
echo "timezone after set...\n";  
var_dump($dateTimeTest);  

Expected result:
----------------
class DateTime#1 (3) {
  public $date =>
  string(26) "1900-01-01 12:20:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(16) "America/New_York"
}
class DateTime#3 (3) {
  public $date =>
  string(26) "1900-01-01 17:20:00.000000"
  public $timezone_type =>
  int(1)
  public $timezone =>
  string(6) "+00:00"
}
timezone after set...
class DateTime#3 (3) {
  public $date =>
  string(26) "1900-01-01 12:20:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(16) "America/New_York"
}


Actual result:
--------------
class DateTime#1 (3) {
  public $date =>
  string(26) "1900-01-01 12:20:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(16) "America/New_York"
}
class DateTime#3 (3) {
  public $date =>
  string(26) "1900-01-01 17:16:02.000000"
  public $timezone_type =>
  int(1)
  public $timezone =>
  string(6) "+00:00"
}
timezone after set...
class DateTime#3 (3) {
  public $date =>
  string(26) "1900-01-01 12:20:00.000000"
  public $timezone_type =>
  int(3)
  public $timezone =>
  string(16) "America/New_York"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-23 13:53 UTC] eric at ericgrysko dot com
I should clarify, *works* as expected on PHP-5.5.24. 5.5.25+ are broken.

Note the minutes/seconds on the actual results.

I'm betting this is somehow related totimezone file change in PHP-5.5.25+ -- see https://bugs.php.net/bug.php?id=69652
 [2015-08-07 12:29 UTC] eric at ericgrysko dot com
Bug present in 5.5.28 as well.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 04:03:35 2021 UTC