Skip to content

Instantly share code, notes, and snippets.

@abresas
Created March 18, 2016 19:19
Show Gist options
  • Save abresas/90cc713ffa2fe1bbf520 to your computer and use it in GitHub Desktop.
Save abresas/90cc713ffa2fe1bbf520 to your computer and use it in GitHub Desktop.
<?php
// returns a timezone that is at the given offset
// taking into consideration if the timezone
// is currently observing DST or not.
//
// offset: timezone offset in seconds
function tz_from_offset($offset) {
$tz = timezone_name_from_abbr(0, $offset, 0);
$date = date_create("now", new DateTimeZone($tz));
if ($date->getOffset() != $offset) {
$tz = timezone_name_from_abbr(0, $offset, 1);
}
return $tz;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment