/** * 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()); } }
/** * 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'); } } }
/** * @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')); }
/** * 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; } }