Last active
July 3, 2024 09:57
-
-
Save aromig/56376f76d4fb653ba83e to your computer and use it in GitHub Desktop.
Detect if British Summer Time is in effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Refactored to check actual timezone abbreviation versus a particular day */ | |
public function is_BST() { | |
$theTime = time(); | |
$tz = new DateTimeZone('Europe/London'); | |
$transition = $tz->getTransitions($theTime, $theTime); | |
$abbr = $transition[0]['abbr']; | |
return $abbr == 'BST' ? true : false; | |
} | |
/* Old gist | |
public function is_BST() { | |
$today = strtotime("today"); | |
$year = date('y'); | |
$BSTstart = strtotime($year."-03-31 last Sunday"); | |
$BSTend = strtotime($year."-10-31 last Sunday"); | |
if ($today < $BSTstart || $today > $BSTend) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment