Skip to content

Commit

Permalink
Ensure Date::formatted_time always has expected timezone
Browse files Browse the repository at this point in the history
Always re-assign the requested timezone in Date::formatted_time
- this will be a no-op if the timezone already matches, otherwise
 it will convert the time as required.

 It is not currently safe to make this a conditional call based on
 comparing the existing timezone name, because of
 facebook/hhvm#2302.
  • Loading branch information
acoulton committed Aug 12, 2014
1 parent ce8288f commit 952d6a8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions classes/Kohana/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,10 @@ public static function formatted_time($datetime_str = 'now', $timestamp_format =
$tz = new DateTimeZone($timezone ? $timezone : date_default_timezone_get());
$time = new DateTime($datetime_str, $tz);

if ($time->getTimeZone()->getName() !== $tz->getName())
{
$time->setTimeZone($tz);
}
// Convert the time back to the expected timezone if required (in case the datetime_str provided a timezone,
// offset or unix timestamp. This also ensures that the timezone reported by the object is correct on HHVM
// (see https://github.com/facebook/hhvm/issues/2302).
$time->setTimeZone($tz);

return $time->format($timestamp_format);
}
Expand Down

0 comments on commit 952d6a8

Please sign in to comment.