Comment 5 for bug 684907

Revision history for this message
NIXin (nixin) wrote :

Here's a proper, working solution, but requires PHP 5 >= 5.3.0.
Replace function getFormattedDate to this:

    function getFormattedDate($ts, $timezone = FALSE)
    {
        if ($timezone === FALSE) {
            $timezone = Date_API::getPreferredTimezone();
        }
        $dateTimeZone = new DateTimeZone($timezone);
        $dateTime = new DateTime($ts, new DateTimeZone('GMT'));
        $dateTime->setTimeZone($dateTimeZone);
        date_default_timezone_set(timezone_name_get($dateTimeZone));
        return strftime("%A, %d %b %Y, %H:%M:%S %Z", $dateTime->getTimestamp());
    }

One comment on this -
This way would be ideal, but there's no support for locales in the DateTime object (so I have to use strftime):
        $dateTimeZone = new DateTimeZone($timezone);
        $dateTime = new DateTime($ts, new DateTimeZone('GMT'));
        $dateTime->setTimeZone($dateTimeZone);
        return $dateTime->format("l, d M Y, H:i:s T");

Cheers