Commit c658c5c7 authored by Zéfling's avatar Zéfling 🎨
Browse files

Ajout des fichiers des jours fériés pour le France et le Japon

parents
<?php
/*
Copyright © Zéfling - 2014 ( http://ikilote.net/fr/Blog/Techno-magis.html )
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The Software is provided "as is", without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. In no event shall the
authors or copyright holders be liable for any claim, damages or other liability,
whether in an action of contract, tort or otherwise, arising from, out of or
in connection with the software or the use or other dealings in the Software.
*/
include_once "Seasons.php";
/**
* Les jours fériés
* @author zefling
* @version 0.1 (2014-06-14)
* @license Expat
*
*/
class Holidays {
const VERSION_CODE = '0.1';
const VERSION_CODE_NUM = '0.1 (2014-06-14)';
/**
* Cette fonction retourne un tableau de timestamp correspondant
* aux jours fériés en France pour une année donnée.
* @param $year int L'année (si null prend d'année courante. Défaut : null)
* @param $reunion bool spécifique à la Réunion (Défaut : false)
* @return array:int la liste timestamp des jours fériés
*/
function getHolidays_France($year = null, $reunion = false) {
if ($year === null) {
$year = intval(date('Y'));
}
// Dimanche de Pâques
$easterDate = easter_date($year);
$easterDay = date('j', $easterDate);
$easterMonth = date('n', $easterDate);
$holidays = array(
// Dates fixes
mktime(0, 0, 0, 1, 1, $year), // 1er janvier
mktime(0, 0, 0, 7, 14, $year), // Fête nationale
mktime(0, 0, 0, 8, 15, $year), // Assomption
mktime(0, 0, 0, 11, 1, $year), // Toussaint
mktime(0, 0, 0, 11, 11, $year), // Armistice
mktime(0, 0, 0, 12, 25, $year), // Noël
// Dates variables
mktime(0, 0, 0, $easterMonth, $easterDay + 1, $year), // lundi de Pâques
mktime(0, 0, 0, $easterMonth, $easterDay + 39, $year), // jeudi de l'Ascension
mktime(0, 0, 0, $easterMonth, $easterDay + 50, $year), // lundi de Pentecôte
);
if ($year >= 1948) {
$holidays[] = mktime(0, 0, 0, 5, 1, $year); // Fête du travail
}
if ($reunion && $year >= 1981) {
$holidays[] = mktime(0, 0, 0, 12, 20, $year); // Abolition de l’esclavage
}
sort($holidays);
return $holidays;
}
/**
* Cette fonction retourne un tableau de timestamp correspondant
* aux jours fériés au Japon pour une année donnée.
* @param $year int L'année (si null prend d'année courante. Défaut : null)
* @return array:int la liste timestamp des jours fériés
*/
public static function getHolidays_Japan($year = null) {
if ($year === null) {
$year = intval(date('Y'));
}
$seasons = new Seasons();
$s = $seasons->computeSeasons($year);
$spring = date_parse($s['spring']);
$autumn = date_parse($s['autumn']);
// golden week
$kinenbi = self::getDay( 3, 5, $year);
$kinenbi_f = count($kinenbi) == 1;
if ($year >= 2007) {
$midori = self::getDay( 4 + ($kinenbi_f ? 0 : 1), 5, $year);
$midori_f = count($midori) == 1;
} else {
$midori = array();
$midori_f = true;
}
$kodomo = self::getDay( 5 + ($kinenbi_f && $midori_f ? 0 : 1), 5, $year);
// merge
$holidays = array_merge(
// Ganjitsu (元日)
self::getDay( 1, 1, $year),
// Seijin no Hi (成人の日) : ~1999 (1月15日) / 2000~ (1月の第2月曜日)
$year < 2000 ? self::getDay( 15, 1, $year) : self::getDayCalc( 1, 2, 1, $year),
// Kenkoku Kinenbi (建国記念の日)
$year >= 1967 ? self::getDay( 11, 2, $year) : array(),
// golden week
self::getDay( 29, 4, $year), // Shōwa no Hi (昭和の日)
$kinenbi, // Kempō Kinenbi (憲法記念日)
$midori, // Midori no Hi (みどりの日) : ~2007 (5月4日)
$kodomo, // Kodomo no Hi (こどもの日)
// Bunka no Hi (文化の日)
self::getDay( 3, 11, $year),
// Kinrō Kansha no Hi (勤労感謝の日)
self::getDay( 23, 11, $year) ,
// Tennō Tanjōbi (天皇誕生日)
$year >= 1989 ? self::getDay( 23, 12, $year) : array(),
// Équinoxes
self::getDay($spring['day'], $spring['month'], $year, $spring['hour'] + 9), // Shunbun no Hi (春分の日)
self::getDay($autumn['day'], $autumn['month'], $year, $autumn['hour'] + 9) // Shūbun no Hi (秋分の日)
);
if ($year >= 1966) {
$holidays = array_merge($holidays,
// Keirō no Hi (敬老の日) : 1966-2002 (9月15日) / 2003~ (9月の第3月曜日)
$year < 2000 ? self::getDay( 15, 9, $year) : self::getDayCalc( 9, 3, 1, $year),
// Taiiku no Hi (体育の日) : 1966-2002 (10月10日) / 2003~ (10月の第2月曜日)
$year < 2000 ? self::getDay( 10, 10, $year) : self::getDayCalc(10, 2, 1, $year)
);
}
// Umi no Hi (海の日) : 1996-2002 (7月20日) / 2003~ (7月の第3月曜日)
if ($year >= 1996) {
$holidays = array_merge($holidays,
$year < 2003 ? self::getDay( 20, 7, $year) : self::getDayCalc( 7, 3, 1, $year)
);
}
// nouveau jour férié à partir de 2016
if ($year >= 2016) {
$holidays[] = self::getDay( 11, 8, $year); // Yama no hi (山の日)
}
sort($holidays);
return $holidays;
}
/**
* Donne un timestamp du jour nième de semaine d'un mois. (ex. 3e lundi de mars)
* @param int $mount mois
* @param int $time nième [jour de la semaine] du mois
* @param int $weekday jour de la semaine (0 : dimanc(($year < 2000) ? self::getDay( 1, 15, $year) : ndi, etc.)
* @param int $year année
* @return number timestamp
*/
public static function getDayCalc ($mount, $time, $weekday, $year) {
$date = mktime(0, 0, 0, $mount, 1, $year);
$jour = date('w' ,$date);
if ($jour == $weekday) {
$i = 1;
} elseif ($jour < $weekday ) {
$i = $weekday - $jour + 1;
} else {
$i = 8 - $jour + $weekday;
}
return self::getDayRecup(mktime(0, 0, 0, $mount, $i + ($time -1) * 7 , $year));
}
/**
* Donne un timestamp du jour courant sauf si c'est un dimanche, proposer le lundi suivant
* @param int $day jour
* @param int $mount mois
* @param int $year année
* @return number timestamp
*/
public static function getDay($day, $mount, $year, $hour = 0) {
return self::getDayRecup(mktime($hour, 0, 0, $mount, $day, $year));
}
/**
* Si c'est un dimanche, retourner le dimanche plus le lundi, sinon le jour seul
* @param int $date timestamp
* @return array timestamp du ou des jours fériés
*/
public static function getDayRecup ($date) {
$dates = array();
$dates[] = $date;
if (date('w' ,$date) == 0) {
$dates[] = strtotime("+1 day", $date);
}
return $dates;
}
}
\ No newline at end of file
<?php
define('K', pi()/180.0);
/**
* Pour récupérer l'heure UT des changements de saison à la minute prêt (±1minute).
* Source : <a href="http://www.jgiesen.de/astro/astroJS/seasons/">Equinoxes and Solstices</a>
*
* @author zefling (portage)
* @version 1.0
* @link http://ikilote.net/fr/Blog/Techno-magis/110.html
*/
class Seasons {
public $y;
public $_Year;
public $yearArray = array();
public $springArray = array();
public $summerArray = array();
public $autumnArray = array();
public $winterArray = array();
public $nSpring;
public $n19;
public $n20;
public $n21;
public $n22;
public function computeSeasonsInter ($year1, $year2) {
if ($year2 < $year1) {
return null;
}
$number = $year2 - $year1;
$this->nSpring = 0;
$this->n19 = 0;
$this->n20 = 0;
$this->n21 = 0;
$this->n22 = 0;
for ($i=0 ; $i<= $number ; $i++) {
$this->y = $year1 + $i;
$this->_Year = $this->y;
$this->yearArray[$i] = $this->y;
$this->y = ($this->y - 2000)/1000;
$this->springArray[$i] = $this->spring();
$this->summerArray[$i] = $this->summer();
$this->autumnArray[$i] = $this->autumn();
$this->winterArray[$i] = $this->winter();
}
return array(
"spring" => $this->springArray,
"summer" => $this->summerArray,
"autumn" => $this->autumnArray,
"winter" => $this->winterArray
);
}
public function computeSeasons($year) {
$this->y = ($year - 2000.0) / 1000.0;
$this->_Year = $year;
return array(
"spring" => $this->spring(),
"summer" => $this->summer(),
"autumn" => $this->autumn(),
"winter" => $this->winter()
);
}
private function S($t) {
return
485*cos(K*(324.96 + 1934.136*$t))
+ 203*cos(K*(337.23 + 32964.467*$t))
+ 199*cos(K*(342.08 + 20.186*$t))
+ 182*cos(K*( 27.85 + 445267.112*$t))
+ 156*cos(K*( 73.14 + 45036.886*$t))
+ 136*cos(K*(171.52 + 22518.443*$t))
+ 77*cos(K*(222.54 + 65928.934*$t))
+ 74*cos(K*(296.72 + 3034.906*$t))
+ 70*cos(K*(243.58 + 9037.513*$t))
+ 58*cos(K*(119.81 + 33718.147*$t))
+ 52*cos(K*(297.17 + 150.678*$t))
+ 50*cos(K*( 21.02 + 2281.226*$t))
+ 45*cos(K*(247.54 + 29929.562*$t))
+ 44*cos(K*(325.15 + 31555.956*$t))
+ 29*cos(K*( 60.93 + 4443.417*$t))
+ 18*cos(K*(155.12 + 67555.328*$t))
+ 17*cos(K*(288.79 + 4562.452*$t))
+ 16*cos(K*(198.04 + 62894.029*$t))
+ 14*cos(K*(199.76 + 31436.921*$t))
+ 12*cos(K*( 95.39 + 14577.848*$t))
+ 12*cos(K*(287.11 + 31931.756*$t))
+ 12*cos(K*(320.81 + 34777.259*$t))
+ 9*cos(K*(227.73 + 1222.114*$t))
+ 8*cos(K*( 15.45 + 16859.074*$t));
}
private function march() {
//var JDE0 = 2451623.80984 + (365242.37404 + (0.05169 - (0.00411 - 0.00057*y)*y)*y)*y;
$JDE0 = 2451623.80984
+ 365242.37404*$this->y
+ 0.05169*$this->y*$this->y
- 0.00411*$this->y*$this->y*$this->y
- 0.00057*$this->y*$this->y*$this->y*$this->y;
$T = ($JDE0 - 2451545.0)/36525.0;
$W = 35999.373*$T - 2.47;
$W = K*$W;
$dL = 1.0 + 0.0334*cos($W) + 0.0007*cos(2*$W);
$marchT = $JDE0 + (0.00001*$this->S($T))/$dL - (66 + ($this->_Year-2000)*1)/86400;
return $marchT;
}
private function june() {
//var JDE0 = 2451716.56767 + (365241.62603 + (0.00325 - (0.00888 - 0.00030*y)*y)*y)*y;
$JDE0 = 2451716.56767
+ 365241.62603*$this->y
+ 0.00325*$this->y*$this->y
+ 0.00888*$this->y*$this->y*$this->y
- 0.00030*$this->y*$this->y*$this->y*$this->y;
$T = ($JDE0 - 2451545.0)/36525.0;
$W = 35999.373*$T - 2.47;
$W = K*$W;
$dL = 1.0 + 0.0334*cos($W) + 0.0007*cos(2*$W);
$juneT = $JDE0 + (0.00001*$this->S($T))/$dL - (66.0 + ($this->_Year-2000)*1.0)/86400.0;
return $juneT;
}
private function september() {
//var JDE0 = 2451810.21715 + (365242.01767 + (0.11575 - (0.00337 - 0.00078*y)*y)*y)*y;
$JDE0 = 2451810.21715
+ 365242.01767*$this->y
- 0.11575*$this->y*$this->y
+ 0.00337*$this->y*$this->y*$this->y
+ 0.00078*$this->y*$this->y*$this->y*$this->y;
$T = ($JDE0 - 2451545.0)/36525.0;
$W = 35999.373*$T - 2.47;
$W = K*$W;
$dL = 1.0 + 0.0334*cos($W) + 0.0007*cos(2*$W);
$septemberT = $JDE0 + (0.00001*$this->S($T))/$dL - (66.0 + ($this->_Year-2000)*1.0)/86400.0;
return $septemberT;
}
private function december() {
//var JDE0 = 2451900.05952 + (365242.74049 + (0.06223 - (0.00823 - 0.00032*y)*y)*y)*y;
$JDE0 = 2451900.05952 + 365242.74049*$this->y - 0.06223*$this->y*$this->y
- 0.00823*$this->y*$this->y*$this->y + 0.00032*$this->y*$this->y*$this->y*$this->y;
$T = ($JDE0 - 2451545.0)/36525.0;
$W = 35999.373*$T - 2.47;
$W = K*$W;
$dL = 1.0 + 0.0334*cos($W) + 0.0007*cos(2*$W);
$decemberT = $JDE0 + (0.00001*$this->S($T))/$dL - (66.0 + ($this->_Year-2000)*1.0)/86400.0;
return $decemberT;
}
private function caldat ($JD) {
$JD0 = floor($JD + 0.5);
$B = floor(($JD0-1867216.25)/36524.25);
$C = $JD0 + $B - floor($B/4) + 1525.0;
$D = floor(($C-122.1)/365.25);
$E = 365.0*$D + floor($D/4);
$F = floor(($C-$E)/30.6001);
$day = floor($C-$E+0.5) - floor(30.6001*$F);
$month = $F - 1 - 12*floor($F/14);
$year = $D - 4715 - floor((7+$month)/10);
$hour = 24.0*($JD + 0.5 - $JD0);
$diff = abs($hour) - floor(abs($hour));
$min = floor(round($diff*60.0));
if ($min == 60) {
$min = 0;
$hour = $hour + 1.0;
}
if ($day == 19) $this->n19++;
if ($day == 20) $this->n20++;
if ($day == 21) $this->n21++;
if ($day == 22) $this->n22++;
return sprintf('%04d-%02d-%02d %02d:%02d', $year, $month, $day, $hour, $min);
}
private function spring() {
$this->nSpring++;
return $this->caldat($this->march());
}
private function summer() {
return $this->caldat($this->june());
}
private function autumn() {
return $this->caldat($this->september());
}
private function winter() {
return $this->caldat($this->december());
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment