Another way to do this is to wrap the function in a class that extends the DateTimeZone class:
<?php
class Helper_DateTimeZone extends DateTimeZone
{
final public static function tzOffsetToName($offset, $isDst = null)
{
if ($isDst === null)
{
$isDst = date('I');
}
$offset *= 3600;
$zone = timezone_name_from_abbr('', $offset, $isDst);
if ($zone === false)
{
foreach (timezone_abbreviations_list() as $abbr)
{
foreach ($abbr as $city)
{
if ((bool)$city['dst'] === (bool)$isDst &&
strlen($city['timezone_id']) > 0 &&
$city['offset'] == $offset)
{
$zone = $city['timezone_id'];
break;
}
}
if ($zone !== false)
{
break;
}
}
}
return $zone;
}
}
?>
Then you could do something like this:
<?php
$Dtz = new Helper_DateTimeZone(Helper_DateTimeZone::tzOffsetToName(-5));
var_dump($Dtz->getName());
string(16) "America/New_York"
?>