Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created February 26, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhughes/e8468f0334a7581d5fe370510137519f to your computer and use it in GitHub Desktop.
Save barryhughes/e8468f0334a7581d5fe370510137519f to your computer and use it in GitHub Desktop.
<?php
/**
* @param string $date (yyyy-mm-dd format)
* @param string $timezone
*
* @return bool|null
*/
function is_dst( $date, $timezone ) {
try {
$datetime = date_create();
$datetime->setTimezone( timezone_open( $timezone ) );
list( $year, $month, $date ) = explode( '-', $date );
$datetime->setDate( $year, $month, $date );
$datetime->setTime( 12, 0 );
return (bool) $datetime->format( 'I' );
} catch ( Exception $e ) {
return null;
}
}
var_dump( is_dst( '2018-02-01', 'America/Vancouver' ) ); // false
var_dump( is_dst( '2018-06-01', 'America/Vancouver' ) ); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment