コード例 #1
0
ファイル: Yearly.php プロジェクト: TYPO3-typo3org/community
    /**
     * special method to build events taking place relative to easter
     * 
     * @param Tx_CzSimpleCal_Utility_DateTime $start
     * @param Tx_CzSimpleCal_Utility_DateTime $end
     * @param Tx_CzSimpleCal_Utility_DateTime $until
     * @see http://de.php.net/manual/en/function.easter-days.php
     */
    protected function buildEaster($start, $end, $until)
    {
        if (!function_exists('easter_days') || !function_exists('easter_date')) {
            throw new RuntimeException('The function easter_days() or easter_date() is not available in your PHP installation.
				The binaries were probably not compiled using --enable-calendar. Contact your
				server administrator to fix this.');
        }
        /**
         * calculate the day offset 
         */
        /**
         * the day of the year of the date given as start
         * 0 is the 1st January
         * 
         * @var integer
         */
        $dayOfYear = date('z', $start->getTimestamp());
        $year = date('Y', $start->getTimestamp());
        $dayOfYearEaster = $this->getDayOfYearForEasterSunday($year);
        /**
         * a string for DateTime->modify() to jump from easter sunday
         * to the desired date
         * null if no jumping required
         * 
         * @var string|null
         */
        $diffDaysStart = $dayOfYear - $dayOfYearEaster;
        $diffDaysStart = sprintf('%+d days', $diffDaysStart);
        /**
         * a string for DateTime->modify() to jump from easter sunday
         * to the desired date
         * null if no jumping required
         * 
         * @var string|null
         */
        $diffDaysEnd = date('z', $end->getTimestamp()) - $dayOfYearEaster;
        $diffDaysEnd = sprintf('%+d days', $diffDaysEnd);
        while ($until >= $start) {
            $this->timeline->add(array('start' => $start->getTimestamp(), 'end' => $end->getTimestamp()));
            // calculate dates for the next year
            $year = $year + 1;
            /**
             * timestamp for easter sunday of a given year
             * @var integer
             */
            $easter = easter_date($year);
            $start->setDate($year, date('n', $easter), date('j', $easter));
            if (!is_null($diffDaysStart)) {
                $start->modify($diffDaysStart);
            }
            $end->setDate($year, date('n', $easter), date('j', $easter));
            if (!is_null($diffDaysEnd)) {
                $end->modify($diffDaysEnd);
            }
        }
    }