facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.13k stars 2.98k forks source link

Zend incompatibility: DateTime timezone incorrectly set #1777

Open jeffchan opened 10 years ago

jeffchan commented 10 years ago

The timezone parameter of the DateTime constructor should only be used as a hint. Currently in HHVM it is stored as the actual timezone.

$tz = new DateTimeZone('Antarctica/South_Pole');
$time = new DateTime('@1301574225', $tz);
var_dump($time->getTimeZone()->getName());

Zend: string(6) "+00:00"

HHVM: string(21) "Antarctica/South_Pole"

jeffchan commented 10 years ago

I'm working on a fix for this

scannell commented 10 years ago

Thanks for reporting this. Glad to hear you're working on it.

ptarjan commented 10 years ago

@jeffchan did you get anywhere on your fix?

SiebelsTim commented 10 years ago

This is actually related to the following Notice from the PHP Manual

Note: The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).

fredemmott commented 10 years ago

We ignore the specified timezone, but still keep it around if you ask for it. If you print it out with format(), you'll see behavior that matches the PHP manual.

This isn't intentional, just saying we're not quite as broken as it seems :p

ptarjan commented 10 years ago

I looked into this and it is much harder than I expected. Our timezone handling is wildly different than php5s.

JanTvrdik commented 9 years ago

Any progress on this? The following is also broken:

$date = new DateTime('1994-11-15T06:12:31-0200');
echo $date->format(DateTime::ISO8601), "\n"; // this is OK
echo $date->getTimezone()->getName(), "\n"; // not OK
echo $date->getTimezone()->getOffset(new DateTime('now')), "\n"; // not OK