Date_Holidays
[ class tree: Date_Holidays ] [ index: Date_Holidays ] [ all elements ]

Source for file Sweden.php

Documentation is available at Sweden.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. /**
  4.  * Driver for determining holidays in Sweden
  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.  * @author   Anders Karlsson <anders.x.karlsson@tdcsong.se>
  22.  * @license  http://www.php.net/license/3_01.txt PHP License 3.0.1
  23.  * @version  CVS: $Id: Sweden.php,v 1.11 2008/03/18 20:35:24 kguest Exp $
  24.  * @link     http://pear.php.net/package/Date_Holidays
  25.  */
  26.  
  27. require_once 'Date/Holidays/Driver/Christian.php';
  28.  
  29. /**
  30.  * Driver class that calculates Swedish holidays
  31.  *
  32.  * @category   Date
  33.  * @package    Date_Holidays
  34.  * @subpackage Driver
  35.  * @author     Anders Karlsson <anders.x.karlsson@tdcsong.se>
  36.  * @license    http://www.php.net/license/3_01.txt PHP License 3.0.1
  37.  * @version    CVS: $Id: Sweden.php,v 1.11 2008/03/18 20:35:24 kguest Exp $
  38.  * @link       http://pear.php.net/package/Date_Holidays
  39.  */
  40. {
  41.     /**
  42.      * Constructor
  43.      *
  44.      * Use the Date_Holidays::factory() method to construct an object of
  45.      * a certain driver
  46.      *
  47.      * @access   protected
  48.      */
  49.     function Date_Holidays_Driver_Sweden()
  50.     {
  51.     }
  52.  
  53.     /**
  54.      * Build the internal arrays that contain data about the calculated holidays
  55.      *
  56.      * @access   protected
  57.      * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  58.      * @throws   object PEAR_ErrorStack
  59.      */
  60.     function _buildHolidays()
  61.     {
  62.         /**
  63.          * New Year's Day
  64.          */
  65.         $this->_addHoliday('newYearsDay',
  66.                            $this->_year . '-01-01',
  67.                            'New Year\'s Day');
  68.  
  69.         /**
  70.          * Epiphanias
  71.          */
  72.         $this->_addHoliday('epiphany',
  73.                            $this->_year . '-01-06',
  74.                            'Epiphany');
  75.  
  76.         /**
  77.          * Easter Sunday
  78.          */
  79.         $easterDate Date_Holidays_Driver_Sweden::calcEaster($this->_year);
  80.         $this->_addHoliday('easter'$easterDate'Easter Sunday');
  81.  
  82.         /**
  83.          * Good Friday / Black Friday
  84.          */
  85.         $goodFridayDate = new Date($easterDate);
  86.         $goodFridayDate->subtractSpan(new Date_Span('2, 0, 0, 0'));
  87.         $this->_addHoliday('goodFriday'$goodFridayDate'Good Friday');
  88.  
  89.         /**
  90.          * Easter Monday
  91.          */
  92.         $this->_addHoliday('easterMonday',
  93.                            $easterDate->getNextDay(),
  94.                            'Easter Monday');
  95.  
  96.         /**
  97.          * May Day
  98.          */
  99.         $this->_addHoliday('mayDay',
  100.                            $this->_year . '-05-01',
  101.                            'May Day');
  102.  
  103.         /**
  104.          * Pentecost (determines Whit Monday, Ascension Day and
  105.          * Feast of Corpus Christi)
  106.          */
  107.         $pentecostDate = new Date($easterDate);
  108.         $pentecostDate->addSpan(new Date_Span('49, 0, 0, 0'));
  109.         $this->_addHoliday('pentecost'$pentecostDate'Pentecost');
  110.  
  111.         /**
  112.          * Ascension Day
  113.          */
  114.         $ascensionDayDate = new Date($pentecostDate);
  115.         $ascensionDayDate->subtractSpan(new Date_Span('10, 0, 0, 0'));
  116.         $this->_addHoliday('ascensionDay'$ascensionDayDate'Ascension Day');
  117.  
  118.         /**
  119.          * Swedish National Day and the Swedish Flag's Day
  120.          */
  121.         $this->_addHoliday('swedenNationalDay',
  122.                            $this->_year . '-06-06',
  123.                            'Swedish National Day and the Swedish Flag\'s Day');
  124.  
  125.         /**
  126.          * Midsummer
  127.          * Saturday past 20th, June
  128.          */
  129.         $juneDate  = new Date($this->_year . '-06-20');
  130.         $dayOfWeek $juneDate->getDayOfWeek();
  131.         $juneDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0'6 - $dayOfWeek)));
  132.         $midSummerDate $juneDate;
  133.         $this->_addHoliday('midSummer'$midSummerDate'Midsummer Day');
  134.  
  135.         /**
  136.          * Midsummer Eve
  137.          * Day before Midsummer.
  138.          */
  139.         $this->_addHoliday('midSummerEve',
  140.                            $midSummerDate->getPrevDay(),
  141.                            'Midsummer Eve');
  142.  
  143.         /**
  144.          * All Saints' Day
  145.          */
  146.         $saintspanDate = new Date($this->_year . '-10-31');
  147.         $dayOfWeek     $saintspanDate->getDayOfWeek();
  148.         $saintspanDate->addSpan(new Date_Span(sprintf('%d, 0, 0, 0',
  149.                                                       6 - $dayOfWeek)));
  150.         $allSaintsDate $saintspanDate;
  151.         $this->_addHoliday('allSaintsDay'$allSaintsDate'All Saints\' Day');
  152.  
  153.         /**
  154.          * Christmas Eve
  155.          */
  156.         $this->_addHoliday('christmasEve'$this->_year . '-12-24''Christmas Eve');
  157.  
  158.         /**
  159.          * Christmas day
  160.          */
  161.         $this->_addHoliday('christmasDay'$this->_year . '-12-25''Christmas Day');
  162.  
  163.         /**
  164.          * Boxing day
  165.          */
  166.         $this->_addHoliday('boxingDay'$this->_year . '-12-26''Boxing Day');
  167.  
  168.         /**
  169.          * New Year's Eve
  170.          */
  171.         $this->_addHoliday('newYearsEve',
  172.                            $this->_year . '-12-31',
  173.                            'New Year\'s Eve');
  174.  
  175.         if (Date_Holidays::errorsOccurred()) {
  176.             return Date_Holidays::getErrorStack();
  177.         }
  178.         return true;
  179.     }
  180.  
  181.     /**
  182.      * Calculates the date for Easter. Actually this methods delegates the
  183.      * calculation to the {@link Date_Holidays_Driver_Christian#calcEaster()} method.
  184.      *
  185.      * @param int $year year
  186.      *
  187.      * @static
  188.      * @access   private
  189.      * @return   object Date 
  190.      */
  191.     function calcEaster($year)
  192.     {
  193.         return Date_Holidays_Driver_Christian::calcEaster($year);
  194.     }
  195.  
  196.     /**
  197.      * Method that returns an array containing the ISO3166 codes that may possibly
  198.      * identify a driver.
  199.      *
  200.      * @static
  201.      * @access public
  202.      * @return array possible ISO3166 codes
  203.      */
  204.     function getISO3166Codes()
  205.     {
  206.         return array('se''swe');
  207.     }
  208. }
  209. ?>

Documentation generated on Thu, 10 Apr 2008 20:00:25 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.