Created
February 26, 2018 18:20
-
-
Save barryhughes/e8468f0334a7581d5fe370510137519f to your computer and use it in GitHub Desktop.
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
<?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