Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aromig
Last active August 26, 2021 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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