PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Date and Time » Date_Holidays » Bug #6350

new holiday listing for sweden

Details

Request #6350new holiday listing for sweden
Submitted2005-12-27 13:53 UTC
Fromanders dot x dot karlsson at tdcsong dot se
Assignedluckec
StatusClosed
PackageDate_Holidays
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2005-12-27 13:53 UTC] anders dot x dot karlsson at tdcsong dot se

Description:
------------
Here's a Holiday driver for Swedish public holidays.

[2005-12-27 13:54 UTC] anders dot x dot karlsson at tdcsong dot se

<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
//
+-----------------------------------------------------------
-----------+
// | PHP Version 4
|
//
+-----------------------------------------------------------
-----------+
// | Copyright (c) 1997-2002 The PHP Group
|
//
+-----------------------------------------------------------
-----------+
// | This source file is subject to version 2.0 of the PHP
license, |
// | that is bundled with this package in the file LICENSE,
and is |
// | available at through the world-wide-web at
|
// | http://www.php.net/license/2_02.txt.
|
// | If you did not receive a copy of the PHP license and
are unable to |
// | obtain it through the world-wide-web, please send a
note to |
// | license@php.net so we can mail you a copy immediately.
|
//
+-----------------------------------------------------------
-----------+
// | Authors: Anders Karlsson
<anders.x.karlsson@tdcsong.se |
//
+-----------------------------------------------------------
-----------+
//
// $Id: Sweden.php,v 1.3 2005/10/18 16:24:29 luckec Exp $

/**
* class that calculates Swedish holidays
*
* @category Date
* @package Date_Holidays
* @subpackage Driver
* @version $Id: Sweden.php,v 1.3 2005/10/18 16:24:29
luckec Exp $
* @author Anders Karlsson
<anders.x.karlsson@tdcsong.se>
*/
class Date_Holidays_Driver_Sweden extends
Date_Holidays_Driver
{
/**
* Constructor
*
* Use the Date_Holidays::factory() method to construct
an object of a certain driver
*
* @access protected
*/
function Date_Holidays_Driver_Sweden()
{
}

/**
* Build the internal arrays that contain data about the
calculated holidays
*
* @access protected
* @return boolean true on success, otherwise a
PEAR_ErrorStack object
* @throws object PEAR_ErrorStack
*/
function _buildHolidays()
{
/**
* New Year's Day
*/
$this->_addHoliday('newYearsDay', $this->_year .
'-01-01', 'New Year\'s Day');

/**
* Epiphanias
*/
$this->_addHoliday('epiphany', $this->_year .
'-01-06', 'Epiphany');

/**
* Easter Sunday
*/
$easterDate =
&Date_Holidays_Driver_Sweden::_calcEaster($this->_year);
$this->_addHoliday('easter', $easterDate, 'Easter
Sunday');

/**
* Good Friday / Black Friday
*/
$goodFridayDate = &new Date($easterDate);
$goodFridayDate->subtractSpan(new Date_Span('2, 0,
0, 0'));
$this->_addHoliday('goodFriday', $goodFridayDate,
'Good Friday');

/**
* Easter Monday
*/
$this->_addHoliday('easterMonday', $easterDate-
>getNextDay(), 'Easter Monday');

/**
* May Day
*/
$this->_addHoliday('mayDay', $this->_year .
'-05-01', 'May Day');

/**
* Pentecost (determines Whit Monday, Ascension Day
and Feast of Corpus Christi)
*/
$pentecostDate = &new Date($easterDate);
$pentecostDate->addSpan(new Date_Span('49, 0, 0,
0'));
$this->_addHoliday('pentecost', $pentecostDate,
'pentecost');

/**
* Ascension Day
*/
$ascensionDayDate = &new Date($pentecostDate);
$ascensionDayDate->subtractSpan(new Date_Span('10,
0, 0, 0'));
$this->_addHoliday('ascensionDay',
$ascensionDayDate, 'Ascension Day');


/**
* Swedish National Day and the Swedish Flag's Day

*/
$this->_addHoliday('swedenNationalDay', $this->_year
. '-06-06', 'Swedish National Day and the Swedish Flag\'s
Day');

/**
* Midsummer
* Saturday past 20th, June
*/
$juneDate = &new Date($this->_year . '-06-20');
$dayOfWeek = $juneDate->getDayOfWeek();
$juneDate->addSpan(new Date_Span(sprintf('%d, 0, 0,
0', 6 - $dayOfWeek)));
$midSummerDate = &$juneDate;
$this->_addHoliday('midSummer', $midSummerDate,
'Midsummer Day');

/**
* All Saints' Day
*/
$saintspanDate = &new Date($this->_year .
'-10-31');
$dayOfWeek = $saintspanDate->getDayOfWeek
();
$saintspanDate->addSpan(new Date_Span(sprintf('%d,
0, 0, 0', 6 - $dayOfWeek)));
$allSaintsDate = &$saintspanDate;
$this->_addHoliday('allSaintsDay', $allSaintsDate,
'All Saints\' Day');




/**
* Christmas Eve
*/
$this->_addHoliday('xmasEve', $this->_year .
'-12-24', 'Christmas Eve');

/**
* Christmas day
*/
$this->_addHoliday('xmasDay', $this->_year .
'-12-25', 'Christmas Day');

/**
* Boxing day
*/
$this->_addHoliday('boxingDay', $this->_year .
'-12-26', 'Boxing Day');

/**
* New Year's Eve
*/
$this->_addHoliday('newYearsEve', $this->_year .
'-12-31', 'New Year\'s Eve');

if (Date_Holidays::errorsOccurred()) {
return Date_Holidays::getErrorStack();
}
return true;
}

/**
* calculates date for Easter
*
* @static
* @access private
* @param int $year year
* @return object Date
*/
function &_calcEaster($year)
{
// golden number
$golden = null;
$century = null;
// 23-Epact (modulo 30)
$epact = null;
// number of days from 21 March to the Paschal Full
Moon
$i = null;
// weekday of the Full Moon (0=Sunday,...)
$j = null;

if ($year > 1582) {
$golden = $year % 19;
$century = floor($year / 100);
$epact = ($century - floor($century / 4) -
floor((8 * $century + 13) / 25)+ 19 * $golden + 15) % 30;
$i = $epact - floor($epact / 28) * (1 -
floor($epact / 28) * floor(29 / ($epact + 1)) * floor((21 -
$golden) / 11));
$j = ($year + floor($year / 4) + $i + 2
- $century + floor($century / 4));
$j = $j % 7;
} else {
$golden = $year % 19;
$i = (19 * $golden + 15) % 30;
$j = ($year + floor($year / 4) + $i) % 7;
}
$l = $i - $j;
$month = 3 + floor(($l + 40) / 44);
$day = $l + 28 - 31 * floor($month / 4);

$date = &new Date(sprintf('%04d-%02d-%02d', $year,
$month, $day));
return $date;
}
}
?>