|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-06-23 13:53 UTC] eric at ericgrysko dot com
[2015-08-07 12:29 UTC] eric at ericgrysko dot com
[2023-04-21 06:23 UTC] sharmaweompal at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
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" }