[PHP] Heure d’hiver en Europe

La fonction existante dans le langage PHP ne retourne pas forcément le bon résultat, alors, voici une classe qui vous permet, sans utiliser la fonction de PHP, de savoir si la date est basée sur l’heure d’hiver ou non

<?php
/**
*   dateime_timezone_daylight.php
*   Copyright (C) MazeSloup - mazesloup [at] gmail [dot] com
*   http://mazesloup.fr
*   http://blog.mazesloup.fr/index.php/post/2010/11/11/php-heure-dhiver-en-europe
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program; if not, write to the Free Software
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/*
 * Permet de savoir si une date est en heure d'hiver ou non
 * Utilisation : ms_SummerTimeInEU::isInWinterTime(strtotime('2010/10/31 04:00'));
 * @return bolean True si nous somme en heure d'hiver, false si nous sommes en heure d'été
 */
class ms_SummerTimeInEU{

	static function getDayOfWinterTime($Year){
		return date('z',strtotime(sprintf("last sunday of october %n",$Year)));
	}

	static function getDayOfSummerTime($Year){
		return date('z',strtotime(sprintf("last sunday of march %n",$Year)));
	}	

	static function isInWinterTime($When){
		$NumberDay=date('z',$When);
		if(($NumberDay<self::getDayOfSummerTime(date('y',$When)))||($NumberDay>self::getDayOfWinterTime(date('y',$When)))){
			return true;
		}else{
			if((($NumberDay==self::getDayOfSummerTime(date('y',$When))&&(date('G',$When)<2)))||(($NumberDay==self::getDayOfWinterTime(date('y',$When))&&(date('G',$When)>3)))){
				return true;
			}else{
				return false;
			}
		}
	}
}
?>

Published by

MazeSloup

What else ?