-
Notifications
You must be signed in to change notification settings - Fork 3.1k
DateTime: issue with timestamps and timezones #4901
Copy link
Copy link
Closed
Labels
Description
I think I may have encountered a bug i DateTime behavior in HHVM - here's the code:
echo "\nDocumenting a bug in HHVM:\n\n";
$date = date_create(null, new DateTimeZone('Europe/Copenhagen'));
$date->setTimestamp(173919600);
echo "expected: 1975-07-07 00:00:00\n result: " . $date->format('Y-m-d H:i:s') . "\n\n";
// attempting work-around: (1)
$date = date_create(null);
$date->setTimestamp(173919600);
$date->setTimezone(new DateTimeZone('Europe/Copenhagen'));
echo "expected: 1975-07-07 00:00:00\n result: " . $date->format('Y-m-d H:i:s') . "\n\n";
// attempting work-around: (2)
$date = date_create_from_format('U', 173919600);
$date->setTimezone(new DateTimeZone('Europe/Copenhagen'));
echo "expected: 1975-07-07 00:00:00\n result: " . $date->format('Y-m-d H:i:s') . "\n\n";Here's the output under PHP 5.3, 5.4, 5.5, 5.6:
Documenting a bug in HHVM:
expected: 1975-07-07 00:00:00
result: 1975-07-07 00:00:00
expected: 1975-07-07 00:00:00
result: 1975-07-07 00:00:00
expected: 1975-07-07 00:00:00
result: 1975-07-07 00:00:00
And here's the output under HHVM:
Documenting a bug in HHVM:
expected: 1975-07-07 00:00:00
result: 1975-07-06 23:00:00
expected: 1975-07-07 00:00:00
result: 1975-07-07 00:00:00
Fatal error: Uncaught exception 'ErrorException' with message 'Argument 2 passed to date_create_from_format() must be an instance of string, int given' in /home/travis/build/mindplay-dk/kissform/test/test.php:724
Stack trace:
#0 (): {closure}()
#1 /home/travis/build/mindplay-dk/kissform/test/test.php(724): date_create_from_format()
#2 {main}
In the first example, setting the timezone up front doesn't seem to work - it looks like setting the timestamp wipes out the timezone? That's not how it behaves under PHP.
As you can see, I found the workaround (1) which is to set the timezone after setting the timestamp.
Possibly unrelated (?) but the argument to date_create_from_format() is an integer in this example, which normally under PHP would automatically be converted. (The obvious work-around is manually casting to a string.)
Here's the build log on Travis-CI.
Reactions are currently unavailable