Exemple #1
0
    /**
     * 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);
            }
        }
    }
 /**
  * Render the supplied unix Tx_CzSimpleCal_Utility_DateTime in a localized human-readable string.
  *
  * @param Tx_CzSimpleCal_Utility_DateTime $start
  * @param Tx_CzSimpleCal_Utility_DateTime $end
  * @return string formatted output
  * @author Christian Zenker <*****@*****.**>
  */
 public function render($start, $end)
 {
     if ($start->format('Y') != $end->format('Y')) {
         return $this->getLL('timespan.from') . ' ' . strftime($this->getLL('timespan.format.else.start'), $start->getTimestamp()) . ' ' . $this->getLL('timespan.to') . ' ' . strftime($this->getLL('timespan.format.else.end'), $end->getTimestamp());
     } elseif ($start->format('m') != $end->format('m')) {
         return $this->getLL('timespan.from') . ' ' . strftime($this->getLL('timespan.format.sameYear.start'), $start->getTimestamp()) . ' ' . $this->getLL('timespan.to') . ' ' . strftime($this->getLL('timespan.format.sameYear.end'), $end->getTimestamp());
     } elseif ($start->format('d') != $end->format('d')) {
         return $this->getLL('timespan.from') . ' ' . strftime($this->getLL('timespan.format.sameMonth.start'), $start->getTimestamp()) . ' ' . $this->getLL('timespan.to') . ' ' . strftime($this->getLL('timespan.format.sameMonth.end'), $end->getTimestamp());
     } else {
         return $this->getLL('timespan.on') . ' ' . strftime($this->getLL('timespan.format.sameDay'), $start->getTimestamp());
     }
 }
Exemple #3
0
 /**
  * special method to build events taking place on odd or even weeks
  * 
  * @param Tx_CzSimpleCal_Utility_DateTime $start
  * @param Tx_CzSimpleCal_Utility_DateTime $end
  * @param Tx_CzSimpleCal_Utility_DateTime $until
  */
 protected function buildOddEven($start, $end, $until)
 {
     $week = $start->format('W') % 2;
     while ($until >= $start) {
         $this->timeline->add(array('start' => $start->getTimestamp(), 'end' => $end->getTimestamp()));
         $start->modify('+2 week');
         $end->modify('+2 week');
         // take care of year switches
         if ($start->format('W') % 2 !== $week) {
             $start->modify('-1 week');
             $end->modify('-1 week');
         }
     }
 }
 /**
  * find all events matching some settings and count them
  * 
  * @param $settings
  * @ugly doing dozens of database requests
  * @return array
  */
 protected function doCountAllWithSettings($settings = array())
 {
     if (!isset($settings['groupBy'])) {
         return $this->setupSettings($settings)->count();
     } else {
         $output = array();
         if ($settings['groupBy'] === 'day') {
             $step = '+1 day';
         } elseif ($settings['groupBy'] === 'week') {
             $step = '+1 week';
         } elseif ($settings['groupBy'] === 'month') {
             $step = '+1 month';
         } elseif ($settings['groupBy'] === 'year') {
             $step = '+1 year';
         } else {
             $step = null;
         }
         $startDate = new Tx_CzSimpleCal_Utility_DateTime('@' . $settings['startDate']);
         $startDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
         $endDate = $settings['endDate'];
         while ($startDate->getTimestamp() < $endDate) {
             if ($step === null) {
                 $tempEndDate = null;
             } else {
                 $tempEndDate = clone $startDate;
                 $tempEndDate->modify($step . ' -1 second');
             }
             $output[] = array('date' => $startDate->format('c'), 'count' => $this->doCountAllWithSettings(array_merge($settings, array('startDate' => $startDate->format('U'), 'endDate' => $tempEndDate ? $tempEndDate->format('U') : null, 'groupBy' => null))));
             if ($step === null) {
                 break;
             } else {
                 $startDate->modify($step);
             }
         }
         return $output;
     }
 }