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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
15 - 13 = ?
Subscribe to this entry?

 
 [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.
 [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: Tue Apr 23 06:01:30 2024 UTC