コード例 #1
0
 /**
  * @dataProvider provideDataForEnhancement
  */
 public function testModifyEnhancement($format, $expected)
 {
     $format = explode('|', $format);
     $init = array_shift($format);
     $format = implode($format, '|');
     $dateTime = new Tx_CzSimpleCal_Utility_DateTime($init);
     $dateTime->modify($format);
     $this->assertEquals($expected, $dateTime->format('U'));
 }
コード例 #2
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);
            }
        }
    }
コード例 #3
0
ファイル: Weekly.php プロジェクト: TYPO3-typo3org/community
 /**
  * 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');
         }
     }
 }
コード例 #4
0
ファイル: EventIndex.php プロジェクト: nicodh/cz_simple_cal
 /**
  * get the end of this event as a dateTimeObject
  * 
  * @return Tx_CzSimpleCal_Utility_DateTime
  */
 public function getDateTimeObjectEnd()
 {
     if (is_null($this->dateTimeObjectEnd)) {
         $this->dateTimeObjectEnd = new Tx_CzSimpleCal_Utility_DateTime('@' . $this->end);
         $this->dateTimeObjectEnd->setTimezone(new DateTimeZone(date_default_timezone_get()));
     }
     return $this->dateTimeObjectEnd;
 }
コード例 #5
0
 /**
  * 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());
     }
 }
コード例 #6
0
 /**
  * get a DateTime object of the recurranceUntil feature
  * 
  * @return DateTime
  */
 public function getDateTimeObjectRecurranceUntil()
 {
     if (is_null($this->recurranceUntilDateTime)) {
         $this->recurranceUntilDateTime = new Tx_CzSimpleCal_Utility_DateTime($this->recurranceUntil > 0 ? '@' . $this->recurranceUntil : Tx_CzSimpleCal_Utility_Config::get('recurrenceEnd'));
         $this->recurranceUntilDateTime->setTimezone(new DateTimeZone($this->timezone));
         $this->recurranceUntilDateTime->setTime(23, 59, 59);
     }
     return $this->recurranceUntilDateTime;
 }
コード例 #7
0
 /**
  * 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;
     }
 }
コード例 #8
0
 /**
  * get the end date of events that should be fetched
  * 
  * @todo getDate support
  * @return DateTime
  */
 protected function getEndDate()
 {
     if (array_key_exists('endDate', $this->actionSettings)) {
         if (isset($this->actionSettings['getDate'])) {
             $date = new Tx_CzSimpleCal_Utility_DateTime($this->actionSettings['getDate']);
             $date->modify($this->actionSettings['endDate']);
         } else {
             $date = new Tx_CzSimpleCal_Utility_DateTime($this->actionSettings['endDate']);
         }
         return $date;
     } else {
         return null;
     }
 }