Skip to content

Instantly share code, notes, and snippets.

@aromig
Last active July 3, 2024 09:57
Show Gist options
  • Save aromig/56376f76d4fb653ba83e to your computer and use it in GitHub Desktop.
Save aromig/56376f76d4fb653ba83e to your computer and use it in GitHub Desktop.
Detect if British Summer Time is in effect
/* 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