public function getIntervals() { if (!$this->_intervals) { $this->_intervals = array(); if (!$this->_from && !$this->_to) { return $this->_intervals; } $dateStart = new Zend_Date($this->_from); $dateEnd = new Zend_Date($this->_to); $t = array(); $firstInterval = true; /** START AITOC FIX **/ if (in_array((string) $this->_period, array('day', 'month', 'year'))) { /** END AITOC FIX **/ while ($dateStart->compare($dateEnd) <= 0) { switch ($this->_period) { case 'day': $t['title'] = $dateStart->toString(Mage::app()->getLocale()->getDateFormat()); $t['start'] = $dateStart->toString('yyyy-MM-dd HH:mm:ss'); $t['end'] = $dateStart->toString('yyyy-MM-dd 23:59:59'); $dateStart->addDay(1); break; case 'month': $t['title'] = $dateStart->toString('MM/yyyy'); $t['start'] = $firstInterval ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-MM-01 00:00:00'); $lastInterval = $dateStart->compareMonth($dateEnd->getMonth()) == 0; $t['end'] = $lastInterval ? $dateStart->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59'); $dateStart->addMonth(1); if ($dateStart->compareMonth($dateEnd->getMonth()) == 0) { $dateStart->setDay(1); } $firstInterval = false; break; case 'year': $t['title'] = $dateStart->toString('yyyy'); $t['start'] = $firstInterval ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-01-01 00:00:00'); $lastInterval = $dateStart->compareYear($dateEnd->getYear()) == 0; $t['end'] = $lastInterval ? $dateStart->setMonth($dateEnd->getMonth())->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-12-31 23:59:59'); $dateStart->addYear(1); if ($dateStart->compareYear($dateEnd->getYear()) == 0) { $dateStart->setMonth(1)->setDay(1); } $firstInterval = false; break; } $this->_intervals[$t['title']] = $t; } /** START AITOC FIX **/ } /** END AITOC FIX **/ } return $this->_intervals; }
/** * Enter description here... * */ public function indexAction() { $currentDate = new Zend_Date(); $currentMonth = $currentDate->toString(Zend_Date::MONTH_SHORT); $currentDay = $currentDate->toString(Zend_Date::DAY_SHORT); $month = $this->_getParam('month', $currentMonth); if (false === is_numeric($month)) { $month = $this->_monthMap[urldecode($month)]; } $currentDate->setMonth($month); $currentDate->setDay(1); $days = $currentDate->toString(Zend_Date::MONTH_DAYS); $this->view->selectedMonth = $month; $this->view->currentMonth = $currentMonth; $this->view->currentDay = $currentDay; $result = Bc_UserDTO::fetchAsArray(array('month' => $month)); $month = array(); for ($i = 1; $i <= $days; $i++) { $data = array(); $data['date'] = $currentDate->toString(Zend_Date::DAY . '.' . Zend_Date::MONTH . '.' . Zend_Date::YEAR); $user = array(); foreach ($result as $birthday) { if ($i == $birthday['birthday']) { $user[] = $birthday; } } $data['user'] = empty($user) ? null : $user; $month[$i] = $data; $currentDate->add('24:00:00', Zend_Date::TIMES); } $this->view->month = $month; }
/** * @ZF-7154 */ public function testZF7154() { $locale = new Zend_Locale('de_AT'); $date = new Zend_Date(1577833200, $locale); $date2 = new Zend_Date(2006, Zend_Date::YEAR); $date->setTimeZone(date_default_timezone_get()); $date->setYear(2000); $date->setMonth('Apr.'); $this->assertSame('2000-04-01T04:00:00+05:00', $date->get(Zend_Date::W3C)); $date->setYear(2004); $date->setMonth('Februar'); $this->assertSame('2004-02-01T04:00:00+05:00', $date->get(Zend_Date::W3C)); }
/** * test looseBehaviour */ public function testLoose() { $date = new Zend_Date(0, 'de'); try { $date->set(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->set(10, 'de'); $this->assertEquals($date->getTimestamp(), 10); try { $date->add(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->add(10, 'de'); $this->assertEquals($date->getTimestamp(), 20); try { $date->sub(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } $date->sub(10, 'de'); $this->assertEquals($date->getTimestamp(), 10); try { $date->compare(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->equals(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isEarlier(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->isLater(null, Zend_Date::YEAR); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareTime(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDate(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareIso(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareArpa(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMonth(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDay(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeekday(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareDayOfYear(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareHour(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareMinute(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareSecond(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->setWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->addWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->subWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } try { $date->compareWeek(null); $this->fail(); } catch (Zend_Date_Exception $e) { // success } }
/** * @param string $year * @param string $month * @param integer $page * @param integer $perPage * @return Zend_Paginator */ public function getListByDate($year, $month = null, $page = 1, $perPage = 10) { $month = (int) $month; if ($month < 1 || $month > 12) { $month = 0; $date = new Zend_Date("{$year}-01-01", Zend_Date::ISO_8601); } else { if (1 == strlen($month)) { $month = "0{$month}"; } $date = new Zend_Date("{$year}-{$month}-01", Zend_Date::ISO_8601); } $from = (int) $date->getTimestamp(); if ($month) { $to = (int) $date->setDay($date->get(Zend_Date::MONTH_DAYS))->getTimestamp(); } else { $to = (int) $date->setMonth(12)->setDay(31)->getTimestamp(); } $list = $this->_getList(); $list->setCondition('date BETWEEN ? AND ?', array($from, $to)); return $this->_paginate($list, $page, $perPage); }
public function getCalendar($month = null, $year = null, $location = null) { $zd = new Zend_Date(); if (is_null($month)) { $month = date('n'); } if (is_null($year)) { $year = date('Y'); } $zd->setMonth($month); $zd->setYear($year); $zd->setDay(1); $calData = array(); $calData['startDay'] = $zd->get(Zend_Date::WEEKDAY_DIGIT); $calData['month'] = $zd->get(Zend_Date::MONTH_SHORT); $calData['monthName'] = $zd->get(Zend_Date::MONTH_NAME); $calData['monthDays'] = $zd->get(Zend_Date::MONTH_DAYS); $calData['year'] = $zd->get(Zend_Date::YEAR); if ($calData['month'] == 12) { $calData['nextMonth'] = 1; } else { $calData['nextMonth'] = $calData['month'] + 1; } $calData['nextYear'] = $calData['year']; if ($calData['nextMonth'] == 1) { $calData['nextYear'] = $calData['year'] + 1; } if ($calData['month'] == 1) { $calData['prevMonth'] = 12; } else { $calData['prevMonth'] = $calData['month'] - 1; } $calData['prevYear'] = $calData['year']; if ($calData['prevMonth'] == 12) { $calData['prevYear'] = $calData['year'] - 1; } $tmpDate = new Zend_Date(); $calData['week'] = $tmpDate->get(Zend_Date::WEEK); $calData['rows'] = array(); $dayCounter = 1; // make sure we don't have an empty row if ($calData['startDay'] > 4) { $numRows = intval($calData['monthDays'] / 5); } else { $numRows = intval($calData['monthDays'] / 6); } for ($x = 0; $x < $numRows; $x++) { $sd = 0; if ($x == 0) { // this sets the first row to start on the correct day of the week for ($y = 0; $y < $calData['startDay']; $y++) { $tmp = array(); $tmp['num'] = ""; $calData['rows'][$x]['days'][$y] = $tmp; } $sd = $calData['startDay']; } $event = new Event(); // put the numbers in the rows for ($z = $sd; $z < 7; $z++) { $tmp = array(); if ($dayCounter <= $calData['monthDays']) { $zd->setDay($dayCounter); // set the week number $calData['rows'][$x]['weekNum'] = $zd->get(Zend_Date::WEEK); $calData['rows'][$x]['weekYear'] = $zd->get(Zend_Date::YEAR); if (isset($calData['rows'][$x - 1]['weekNum'])) { if ($calData['rows'][$x - 1]['weekNum'] == 52) { $calData['rows'][$x]['weekNum'] = "01"; $calData['rows'][$x]['weekYear'] = $year + 1; } } $tmp['num'] = $dayCounter; $calData['rows'][$x]['days'][$z] = $tmp; $where = $event->getAdapter()->quoteInto('date = ?', $year . "-" . $month . "-" . $dayCounter); $where .= " AND "; $where .= $event->getAdapter()->quoteInto('status = ?', 'open'); if (!is_null($locationId)) { $where .= " AND "; $where .= $event->getAdapter()->quoteInto('locationId = ?', $locationId); } $events = $event->fetchAll($where, 'startTime')->toArray(); $calData['rows'][$x]['days'][$z]['numEvents'] = count($events); } else { $tmp['num'] = ""; $calData['rows'][$x]['days'][$z] = $tmp; } $dayCounter++; } } return $calData; }
/** * The main scheduler page. This allows a user to view and edit the schedule. Users * will almost certainly need access to this entire controller to make the * scheduler work properly and look right. * */ public function indexAction() { $this->view->acl = array('addEvent' => $this->_helper->hasAccess('add-event')); $get = Zend_Registry::get('getFilter'); if (isset($get->workshopId)) { $workshopId = $get->workshopId; $this->view->workshopId = $workshopId; $this->view->startInAddMode = 1; } if (isset($get->startYear)) { $this->view->startYear = $get->startYear; } else { $this->view->startYear = date('Y'); } if (isset($get->startMonth)) { $this->view->startMonth = $get->startMonth; } else { $this->view->startMonth = date('m'); } $eventId = null; if (isset($get->eventId)) { $eventId = $get->eventId; $this->view->eventId = $eventId; $this->view->startInEditMode = 1; $e = new Event(); $thisEvent = $e->find($eventId)->toArray(); $this->view->locationId = $thisEvent['locationId']; } $zd = new Zend_Date(); $this->view->workshopLength = mktime(1, 0, 0, 1, 1, 1970); $this->view->startTime = mktime(0, 0, 0, 1, 1, 1970); $this->view->endTime = mktime(23, 30, 0, 1, 1, 1970); $this->view->baseTime = mktime(0, 0, 0, 1, 1, 1970); $this->view->today = $zd->get(Zend_Date::MONTH) . "/" . $zd->get(Zend_Date::DAY) . "/" . $zd->get(Zend_Date::YEAR); $this->view->thisYear = $zd->get(Zend_Date::YEAR); $this->view->thisWeek = $zd->get(Zend_Date::WEEK); if (!is_null($eventId)) { $tmpDate = explode('-', $thisEvent['date']); $zd->setYear($tmpDate[0]); $zd->setMonth($tmpDate[1]); $zd->setDay($tmpDate[2]); } $this->view->year = $zd->get(Zend_Date::YEAR); $this->view->week = $zd->get(Zend_Date::WEEK); $this->_helper->pageTitle('workshop-schedule-index:title'); $workshop = new Workshop(); $where = $workshop->getAdapter()->quoteInto('status = ?', 'enabled'); $workshops = $workshop->fetchAll($where, 'title'); $workshopList = array(); $workshopList[0] = ""; foreach ($workshops as $w) { $workshopList[$w->workshopId] = $w->title; } $this->view->workshops = $workshopList; $location = new Location(); $where = $location->getAdapter()->quoteInto('status = ?', 'enabled'); $locations = $location->fetchAll($where, 'name'); if (count($locations) == 0) { $this->_helper->redirector->gotoUrl('/workshop/schedule/noLocationsFound'); } foreach ($locations as $l) { $locationList[$l->locationId] = $l->name; } $this->view->locationList = $locationList; //get all the users available for the instructor list $profile = new Ot_Account(); $profiles = $profile->fetchAll(null, array('lastName', 'firstName'))->toArray(); $instructors = array(); foreach ($profiles as $p) { $instructors[$p['username']] = $p['lastName'] . ", " . $p['firstName']; } $this->view->messages = $this->_helper->flashMessenger->getMessages(); $this->view->instructors = $instructors; $this->view->headScript()->appendFile($this->view->baseUrl() . '/public/scripts/jMonthCalendar-1.1.0.js'); //$this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jMonthCalendar-1.2.2.js'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/public/scripts/jquery.bt.min.js'); }
/** * Get Interval for a year * * @param Zend_Date $dateStart * @param Zend_Date $dateEnd * @param bool $firstInterval * @return array */ protected function _getYearInterval(Zend_Date $dateStart, Zend_Date $dateEnd, $firstInterval) { $interval = array(); $interval['period'] = $dateStart->toString('yyyy'); $interval['start'] = $firstInterval ? $dateStart->toString('yyyy-MM-dd 00:00:00') : $dateStart->toString('yyyy-01-01 00:00:00'); $lastInterval = $dateStart->compareYear($dateEnd->getYear()) == 0; $interval['end'] = $lastInterval ? $dateStart->setMonth($dateEnd->getMonth())->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59') : $dateStart->toString('yyyy-12-31 23:59:59'); $dateStart->addYear(1); if ($dateStart->compareYear($dateEnd->getYear()) == 0) { $dateStart->setMonth(1)->setDay(1); } return $interval; }
/** * 取得某个预定义时间段 * * @static * @param integer $interval * @param string $forceUnit * @param integer $timestamp * @return array */ public static function getPredefinedRange($interval, $forceUnit = null, $timestamp = null) { if (empty($timestamp)) { $timestamp = time(); } $start = new Zend_Date($timestamp); $end = new Zend_Date($timestamp); switch ($interval) { case self::TODAY: $start->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::HOUR; break; case self::YESTODAY: $start->subDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addDay(1); $unit = Zend_Date::HOUR; break; case self::TOMORROW: $start->addDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addDay(1); $unit = Zend_Date::HOUR; break; case self::THIS_MONTH: $start->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::DAY; break; case self::THIS_YEAR: $start->setMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end->addMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::DAY; break; case self::THIS_SEASON: $start->setMonth(3 * floor(($start->toValue('M') - 1) / 3) + 1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $unit = Zend_Date::DAY; case self::RECENT_24HOUR: $start->subHour(24); $unit = Zend_Date::HOUR; break; case self::RECENT_48HOUR: $start->subHour(48); $unit = Zend_Date::HOUR; break; case self::RECENT_1WEEK: $start->subWeek(1); $unit = Zend_Date::DAY; break; case self::RECENT_1MONTH: $start->subMonth(1); $unit = Zend_Date::DAY; break; case self::RECENT_24MONTH: $start->subMonth(24); $unit = Zend_Date::DAY; break; case self::LAST_1MONTH: $start->subMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addMonth(1); $unit = Zend_Date::DAY; break; case self::LAST_1YEAR: $start->subYear(1)->setMonth(1)->setDay(1)->setHour(0)->setMinute(0)->setSecond(0); $end = clone $start; $end->addYear(1); $unit = Zend_Date::DAY; break; case self::ENTIRE_DAY: $start->setDate(self::ERA_DATE, self::ZF_DATE_FORMAT)->setTime(self::ERA_TIME, self::ZF_TIME_FORMAT); $end->addDay(1); $unit = Zend_Date::DAY; break; default: $unit = Zend_Date::SECOND; } if (!empty($forceUnit)) { $unit = $forceUnit; } $start = max(self::truncateDatetime($start, $unit), self::truncateDatetime(self::ERA_DATETIME, $unit)); $end = max(self::truncateDatetime($end, $unit), self::truncateDatetime(self::ERA_DATETIME, $unit)); return compact('start', 'end', 'unit'); }