PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/php-pear-Date-Holidays-0.21.6/Date_Holidays-0.21.6/Date/Holidays/Driver/Christian.php

#
PHP | 427 lines | 170 code | 50 blank | 207 comment | 8 complexity | ca39ba79ff2d45e6481ad6e4a5f3bdbf MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4. * Driver for Christian holidays
  5. *
  6. * PHP Version 4
  7. *
  8. * Copyright (c) 1997-2008 The PHP Group
  9. *
  10. * This source file is subject to version 3.0 of the PHP license,
  11. * that is bundled with this package in the file LICENSE, and is
  12. * available at through the world-wide-web at
  13. * http://www.php.net/license/3_01.txt.
  14. * If you did not receive a copy of the PHP license and are unable to
  15. * obtain it through the world-wide-web, please send a note to
  16. * license@php.net so we can mail you a copy immediately.
  17. *
  18. * @category Date
  19. * @package Date_Holidays
  20. * @author Carsten Lucke <luckec@tool-garage.de>
  21. * @license http://www.php.net/license/3_01.txt PHP License 3.0.1
  22. * @version CVS: $Id: Christian.php 323603 2012-02-27 22:03:42Z kguest $
  23. * @link http://pear.php.net/package/Date_Holidays
  24. */
  25. /**
  26. * class that calculates Christian holidays
  27. *
  28. * @category Date
  29. * @package Date_Holidays
  30. * @subpackage Driver
  31. * @author Carsten Lucke <luckec@tool-garage.de>
  32. * @license http://www.php.net/license/3_01.txt PHP License 3.0.1
  33. * @version CVS: $Id: Christian.php 323603 2012-02-27 22:03:42Z kguest $
  34. * @link http://pear.php.net/package/Date_Holidays
  35. */
  36. class Date_Holidays_Driver_Christian extends Date_Holidays_Driver
  37. {
  38. /**
  39. * this driver's name
  40. *
  41. * @access protected
  42. * @var string
  43. */
  44. var $_driverName = 'Christian';
  45. /**
  46. * Constructor
  47. *
  48. * Use the Date_Holidays::factory() method to construct an object of a
  49. * certain driver
  50. *
  51. * @access protected
  52. */
  53. function Date_Holidays_Driver_Christian()
  54. {
  55. }
  56. /**
  57. * Build the internal arrays that contain data about the calculated holidays
  58. *
  59. * @access protected
  60. * @return boolean true on success, otherwise a PEAR_ErrorStack object
  61. * @throws object PEAR_ErrorStack
  62. */
  63. function _buildHolidays()
  64. {
  65. /**
  66. * Circumcision of Jesus
  67. */
  68. $this->_addHoliday('jesusCircumcision',
  69. $this->_year . '-01-01',
  70. 'Circumcision of Jesus');
  71. /**
  72. * Epiphanias
  73. */
  74. $this->_addHoliday('epiphany', $this->_year . '-01-06', 'Epiphany');
  75. /**
  76. * Cleaning of Mari?
  77. */
  78. $this->_addHoliday('mariaCleaning',
  79. $this->_year . '-02-02',
  80. 'Cleaning of Maria');
  81. /**
  82. * Josef's Day
  83. */
  84. $this->_addHoliday('josefsDay',
  85. $this->_year . '-03-19',
  86. 'Josef\'s Day');
  87. /**
  88. * Maria Announcement
  89. */
  90. $this->_addHoliday('mariaAnnouncement',
  91. $this->_year . '-03-25',
  92. 'Maria Announcement');
  93. /**
  94. * Easter Sunday
  95. */
  96. $easterDate = Date_Holidays_Driver_Christian::calcEaster($this->_year);
  97. $this->_addHoliday('easter', $easterDate, 'Easter Sunday');
  98. /**
  99. * Palm Sunday
  100. */
  101. $palmSundayDate = $this->_addDays($easterDate, -7);
  102. $this->_addHoliday('palmSunday', $palmSundayDate, 'Palm Sunday');
  103. /**
  104. * Passion Sunday
  105. */
  106. $passionSundayDate = $this->_addDays($palmSundayDate, -7);
  107. $this->_addHoliday('passionSunday', $passionSundayDate, 'Passion Sunday');
  108. /**
  109. * Painful Friday
  110. */
  111. $painfulFridayDate = $this->_addDays($palmSundayDate, -2);
  112. $this->_addHoliday('painfulFriday', $painfulFridayDate, 'Painful Friday');
  113. /**
  114. * White Sunday
  115. */
  116. $whiteSundayDate = $this->_addDays($easterDate, 7);
  117. $this->_addHoliday('whiteSunday', $whiteSundayDate, 'White Sunday');
  118. /**
  119. * Ash Wednesday
  120. */
  121. $ashWednesdayDate = $this->_addDays($easterDate, -46);
  122. $this->_addHoliday('ashWednesday', $ashWednesdayDate, 'Ash Wednesday');
  123. /**
  124. * Good Friday / Black Friday
  125. */
  126. $goodFridayDate = $this->_addDays($easterDate, -2);
  127. $this->_addHoliday('goodFriday', $goodFridayDate, 'Good Friday');
  128. /**
  129. * Green Thursday
  130. */
  131. $this->_addHoliday('greenThursday',
  132. $goodFridayDate->getPrevDay(),
  133. 'Green Thursday');
  134. /**
  135. * Easter Monday
  136. */
  137. $this->_addHoliday('easterMonday',
  138. $easterDate->getNextDay(),
  139. 'Easter Monday');
  140. /**
  141. * Whitsun (determines Whit Monday, Ascension Day and
  142. * Feast of Corpus Christi)
  143. */
  144. $whitsunDate = $this->_addDays($easterDate, 49);
  145. $this->_addHoliday('whitsun', $whitsunDate, 'Whitsun');
  146. /**
  147. * Request Sunday
  148. */
  149. $requestSunday = $this->_addDays($whitsunDate, -14);
  150. $this->_addHoliday('requestSunday', $requestSunday, 'Request Sunday');
  151. /**
  152. * Ascension Day
  153. */
  154. $ascensionDayDate = $this->_addDays($whitsunDate, -10);
  155. $this->_addHoliday('ascensionDay', $ascensionDayDate, 'Ascension Day');
  156. /**
  157. * Whit Monday
  158. */
  159. $this->_addHoliday('whitMonday', $whitsunDate->getNextDay(), 'Whit Monday');
  160. /**
  161. * Haunting of Mari?
  162. */
  163. $this->_addHoliday('mariaHaunting',
  164. $this->_year . '-05-31',
  165. 'Haunting of Maria');
  166. /**
  167. * Trinitatis
  168. */
  169. $trinitatisDate = $this->_addDays($whitsunDate, 7);
  170. $this->_addHoliday('trinitatis',
  171. $trinitatisDate,
  172. 'Trinitatis');
  173. /**
  174. * Feast of Corpus Christi
  175. */
  176. $corpusChristiDate = $this->_addDays($whitsunDate, 11);
  177. $this->_addHoliday('corpusChristi',
  178. $corpusChristiDate,
  179. 'Feast of Corpus Christi');
  180. /**
  181. * Heart of Jesus
  182. *
  183. * Friday of the 3rd week past Whitsun
  184. */
  185. $heartJesusDate = $this->_addDays($whitsunDate, 19);
  186. $this->_addHoliday('heartJesus',
  187. $heartJesusDate,
  188. 'Heart of Jesus celebration');
  189. /**
  190. * Johannis celebration
  191. */
  192. $this->_addHoliday('johannisCelebration',
  193. $this->_year . '-06-24',
  194. 'Johannis celebration');
  195. /**
  196. * Petrus and Paulus
  197. */
  198. $this->_addHoliday('petrusAndPaulus',
  199. $this->_year . '-06-29',
  200. 'Petrus and Paulus');
  201. /**
  202. * Ascension of Maria
  203. */
  204. $this->_addHoliday('mariaAscension',
  205. $this->_year . '-08-15',
  206. 'Ascension of Maria');
  207. /**
  208. * Celebration of raising the Cross
  209. */
  210. $this->_addHoliday('crossRaising',
  211. $this->_year . '-09-14',
  212. 'Celebration of raising the Cross');
  213. /**
  214. * Thanks Giving
  215. *
  216. * Sunday past Michaelis (29. September)
  217. */
  218. $michaelisDate = new Date($this->_year . '-09-29');
  219. $dayOfWeek = $michaelisDate->getDayOfWeek();
  220. $michaelisDate = $this->_addDays($michaelisDate, 7 - $dayOfWeek);
  221. $thanksGivingDate = $michaelisDate;
  222. $this->_addHoliday('thanksGiving', $thanksGivingDate, 'Thanks Giving');
  223. /**
  224. * Kermis
  225. *
  226. * 3rd Sunday in October
  227. */
  228. $kermisDate = new Date($this->_year . '-10-01');
  229. $dayOfWeek = $kermisDate->getDayOfWeek();
  230. if ($dayOfWeek != 0) {
  231. $kermisDate = $this->_addDays($kermisDate, 7 - $dayOfWeek);
  232. }
  233. $kermisDate = $this->_addDays($kermisDate, 14);
  234. $this->_addHoliday('kermis', $kermisDate, 'Kermis');
  235. /**
  236. * Reformation Day
  237. */
  238. $this->_addHoliday('reformationDay',
  239. $this->_year . '-10-31',
  240. 'Reformation Day');
  241. /**
  242. * All Saints' Day
  243. */
  244. $this->_addHoliday('allSaintsDay',
  245. $this->_year . '-11-01',
  246. 'All Saints\' Day');
  247. /**
  248. * All Souls' Day
  249. */
  250. $this->_addHoliday('allSoulsDay',
  251. $this->_year . '-11-02',
  252. 'All Souls\' Day');
  253. /**
  254. * Martin's Day
  255. */
  256. $this->_addHoliday('martinsDay', $this->_year . '-11-11', 'Martin\'s Day');
  257. /**
  258. * 4th Advent
  259. */
  260. $Advent4Date = new Date($this->_year . '-12-25');
  261. $dayOfWeek = $Advent4Date->getDayOfWeek();
  262. if ($dayOfWeek == 0) {
  263. $dayOfWeek = 7;
  264. }
  265. $Advent4Date = $this->_addDays($Advent4Date, -$dayOfWeek);
  266. $this->_addHoliday('advent4', $Advent4Date, '4th Advent');
  267. /**
  268. * 1st Advent
  269. */
  270. $Advent1Date = $this->_addDays($Advent4Date, -21);
  271. $this->_addHoliday('advent1', $Advent1Date, '1st Advent');
  272. /**
  273. * 2nd Advent
  274. */
  275. $Advent2Date = $this->_addDays($Advent4Date, -14);
  276. $this->_addHoliday('advent2', $Advent2Date, '2nd Advent');
  277. /**
  278. * 3rd Advent
  279. */
  280. $Advent3Date = $this->_addDays($Advent4Date, -7);
  281. $this->_addHoliday('advent3', $Advent3Date, '3rd Advent');
  282. /**
  283. * Death' Sunday
  284. */
  285. $deathSundayDate = $this->_addDays($Advent1Date, -7);
  286. $this->_addHoliday('deathSunday', $deathSundayDate, 'Death\' Sunday');
  287. /**
  288. * Day of Repentance
  289. */
  290. $dayOfRepentance = $this->_addDays($deathSundayDate, -4);
  291. $this->_addHoliday('dayOfRepentance', $dayOfRepentance, 'Day of Repentance');
  292. /**
  293. * St. Nicholas' Day
  294. */
  295. $this->_addHoliday('stNicholasDay',
  296. $this->_year . '-12-06',
  297. 'St. Nicholas\' Day');
  298. /**
  299. * Maria' conception
  300. */
  301. $this->_addHoliday('mariaConception',
  302. $this->_year . '-12-08',
  303. 'Conception of Maria');
  304. /**
  305. * Christmas Eve
  306. */
  307. $this->_addHoliday('christmasEve', $this->_year . '-12-24', 'Christmas Eve');
  308. /**
  309. * Christmas day
  310. */
  311. $this->_addHoliday('christmasDay', $this->_year . '-12-25', 'Christmas Day');
  312. /**
  313. * Boxing day
  314. */
  315. $this->_addHoliday('boxingDay', $this->_year . '-12-26', 'Boxing Day');
  316. /**
  317. * New Year's Eve
  318. */
  319. $this->_addHoliday('newYearsEve',
  320. $this->_year . '-12-31',
  321. 'New Year\'s Eve');
  322. if (Date_Holidays::errorsOccurred()) {
  323. return Date_Holidays::getErrorStack();
  324. }
  325. return true;
  326. }
  327. /**
  328. * Calculates date for Easter using the Gaussian algorithm.
  329. *
  330. * @param int $year year
  331. *
  332. * @static
  333. * @access public
  334. * @return object Date
  335. */
  336. function calcEaster($year)
  337. {
  338. if (function_exists("easter_days")) {
  339. $easter = new Date();
  340. $easter->setDate(
  341. strtotime("$year-03-21 + " . easter_days($year) . " days"),
  342. DATE_FORMAT_UNIXTIME
  343. );
  344. return $easter;
  345. }
  346. // golden number
  347. $golden = null;
  348. $century = null;
  349. // 23-Epact (modulo 30)
  350. $epact = null;
  351. // number of days from 21 March to the Paschal Full Moon
  352. $i = null;
  353. // weekday of the Full Moon (0=Sunday,...)
  354. $j = null;
  355. if ($year > 1582) {
  356. $golden = $year % 19;
  357. $century = floor($year / 100);
  358. $l = floor($century / 4);
  359. $epact = ($century - $l - floor((8 * $century + 13) / 25)
  360. + 19 * $golden + 15) % 30;
  361. $i = $epact - floor($epact / 28) * (1 - floor($epact / 28) *
  362. floor(29 / ($epact + 1)) * floor((21 - $golden) / 11));
  363. $j = ($year + floor($year / 4) + $i + 2 - $century + $l);
  364. $j = $j % 7;
  365. } else {
  366. $golden = $year % 19;
  367. $i = (19 * $golden + 15) % 30;
  368. $j = ($year + floor($year / 4) + $i) % 7;
  369. }
  370. $l = $i - $j;
  371. $month = 3 + floor(($l + 40) / 44);
  372. $day = $l + 28 - 31 * floor($month / 4);
  373. $date = new Date(sprintf('%04d-%02d-%02d', $year, $month, $day));
  374. return $date;
  375. }
  376. }
  377. ?>