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
 [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

Pull Requests

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.
 [2023-04-21 06:23 UTC] sharmaweompal at gmail dot com
Metaworld90 is here to provide you with all popu, blogs, and articles or news etc. More info:(https://metaworld90.com)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 07:01:27 2024 UTC