/** * @param $filter * * @return mixed */ protected function _processFilter($filter) { $period = AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_THIRTY_DAYS; if (array_key_exists('period', $filter)) { $period = intval($filter['period']); } $filter['period'] = $period; $fromDate = new Zend_Date(); $toDate = new Zend_Date(); $fromDate->setHour(23)->setMinute(59)->setSecond(59); $toDate->setHour(23)->setMinute(59)->setSecond(59); switch ($period) { case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_TODAY: break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_YESTERDAY: $fromDate->subDay(1); $toDate->subDay(1); break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_THIS_WEEK: $firstDayOfWeek = (int) Mage::getStoreConfig('general/locale/firstday'); if ($firstDayOfWeek === 0) { $firstDayOfWeek = 7; } $fromDate->setWeekday($firstDayOfWeek); if ($firstDayOfWeek > (int) $fromDate->toString('e')) { $fromDate->subWeek(1); } break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_WEEK: $fromDate->subWeek(1); $toDate->subWeek(1); $firstDayOfWeek = (int) Mage::getStoreConfig('general/locale/firstday'); if ($firstDayOfWeek === 0) { $firstDayOfWeek = 7; } $fromDate->setWeekday($firstDayOfWeek); if ($firstDayOfWeek > (int) $fromDate->toString('e')) { $fromDate->subWeek(1); } $lastDayOfWeek = $firstDayOfWeek - 1; if ($lastDayOfWeek < 1) { $lastDayOfWeek = 7; } $toDate->setWeekday($lastDayOfWeek); break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_THIS_MONTH: $fromDate->setDay(1); break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_MONTH: $fromDate->subMonth(1)->setDay(1); $toDate->setDay(1)->subDay(1); break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_SIX_MONTHS: $fromDate->subMonth(6); break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_CUSTOM: $_reversed = false; $_now = new Zend_Date(null, 'dd/MM/y'); try { $_fromDate = new Zend_Date($filter['from_date'], 'dd/MM/y'); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('aw_hdu3')->__('Please select correct "From" date value')); $_fromDate = clone $_now; } try { $_toDate = new Zend_Date($filter['to_date'], 'dd/MM/y'); if ($_fromDate->compare($_toDate) > 0) { $_reversed = true; } } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('aw_hdu3')->__('Please select correct "To" date value')); $_toDate = clone $_now; } if ($_reversed) { $fromDate = $_toDate; $toDate = $_fromDate; } else { $fromDate = $_fromDate; $toDate = $_toDate; } break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_SEVEN_DAYS: $fromDate->subDay(6); break; case AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::PERIOD_LAST_THIRTY_DAYS: $fromDate->subDay(29); break; } $filter['from_date'] = $fromDate; $filter['to_date'] = $toDate; if (!array_key_exists('group', $filter)) { $filter['group'] = AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::GROUP_BY_WEEK; } if (!array_key_exists('agents[]', $filter)) { $filter['agents[]'] = $this->_getAgentIds(); } if (!array_key_exists('report', $filter)) { $filter['report'] = AW_Helpdesk3_Block_Adminhtml_Statistic_Agent_View_Chart::REPORT_FIRST_REPLY_AVG_TIME; } return $filter; }
/** * Test for ZF-5203 */ public function testMultiByteWeekdaysShouldNotBeTruncated() { $date1 = new Zend_Date('pl'); $date1->setWeekday(3); $this->assertEquals('ś', $date1->get(Zend_Date::WEEKDAY_NARROW)); }
public function getWeek($week, $year, $locationId = null) { $zd = new Zend_Date(); $event = new Event(); $workshop = new Workshop(); if ($week == 1) { $calData['prevWeekNum'] = 52; $calData['prevYear'] = $year - 1; $calData['nextWeekNum'] = 2; $calData['nextYear'] = $year; } else { if ($week == 52) { $calData['prevWeekNum'] = 51; $calData['prevYear'] = $year; $calData['nextWeekNum'] = 1; $calData['nextYear'] = $year + 1; } else { $calData['prevWeekNum'] = $week - 1; $calData['prevYear'] = $year; $calData['nextWeekNum'] = $week + 1; $calData['nextYear'] = $year; } } // go back to the current week $zd->setYear($year); $zd->setWeek($week); // set the weekday to sunday for the display purposes $zd->setWeekday("sunday"); $month = $zd->get(Zend_Date::MONTH_SHORT); for ($x = 0; $x < 7; $x++) { $tmp = array(); $tmp['startDay'] = $zd->get(Zend_Date::WEEKDAY_DIGIT); $tmp['month'] = $zd->get(Zend_Date::MONTH_SHORT); $tmp['day'] = $zd->get(Zend_Date::DAY_SHORT); $tmp['monthName'] = $zd->get(Zend_Date::MONTH_NAME); $tmp['monthDays'] = $zd->get(Zend_Date::MONTH_DAYS); $tmp['year'] = $zd->get(Zend_Date::YEAR); $tmp['weekNum'] = $zd->get(Zend_Date::WEEK); $tmp['date'] = $zd->getTimestamp(); $calData[$x] = $tmp; $where = $event->getAdapter()->quoteInto('date = ?', $tmp['year'] . "-" . $tmp['month'] . "-" . $tmp['day']); $where .= " AND "; $where .= $event->getAdapter()->quoteInto('status = ?', 'open'); if (!is_null($locationId)) { $where .= " AND "; $where .= $event->getAdapter()->quoteInto('locationId = ?', $locationId); } $calData[$x]['events'] = $event->fetchAll($where, 'startTime')->toArray(); for ($y = 0; $y < count($calData[$x]['events']); $y++) { if (isset($calData[$x]['events'][$y]['workshopId'])) { $tmpStart = strtotime($calData[$x]['events'][$y]['startTime']); $tmpEnd = strtotime($calData[$x]['events'][$y]['endTime']); $calData[$x]['events'][$y]['numMinutes'] = ($tmpEnd - $tmpStart) / 60; $workshopId = $calData[$x]['events'][$y]['workshopId']; $calData[$x]['events'][$y]['workshop'] = $workshop->find($workshopId)->toArray(); } } $zd->addDay(1); } $calData['weekNum'] = $zd->get(Zend_Date::WEEK); $calData['year'] = $year; return $calData; }
/** * 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 array $statistics (array('2014-01-01' => 2,'2014-01-02' => 0)) * @param int $periodType * * @return array (array('2014-01' => 2)) */ public function getGroupedByPeriod($statistics, $periodType) { if ($periodType == self::PERIOD_DAY_TYPE) { return $statistics; } ksort($statistics); //get first key $intervalDate = new Zend_Date(key($statistics), Varien_Date::DATE_INTERNAL_FORMAT); //reset day to 1 $intervalDate->setDay(1); if ($periodType == self::PERIOD_WEEK_TYPE) { //for week period need set start interval like 2014-01-07 $firstWeekDay = (int) Mage::getStoreConfig('general/locale/firstday') == 0 ? 7 : (int) Mage::getStoreConfig('general/locale/firstday'); $intervalDate->setWeekday($firstWeekDay); if ($intervalDate->toString(Varien_Date::DATE_INTERNAL_FORMAT) == key($statistics)) { $intervalDate->addWeek(1); } $intervalDate->subDay(1); } $result = array(); foreach ($statistics as $key => $value) { if (!$this->_isInPeriodInterval($intervalDate, $key, $periodType)) { $this->_setPeriodIntervalIndex($intervalDate, $key, $periodType); } $intervalIndex = $intervalDate->toString($this->_getPeriodIntervalDateFormat($periodType)); if ($periodType == self::PERIOD_WEEK_TYPE) { $_prevWeek = clone $intervalDate; $_prevWeek->subWeek(1); $_prevWeek->addDay(1); $_prevWeekIndex = $_prevWeek->toString($this->_getPeriodIntervalDateFormat($periodType)); $result[$_prevWeekIndex . '/' . $intervalIndex] = (array_key_exists($_prevWeekIndex . '/' . $intervalIndex, $result) ? $result[$_prevWeekIndex . '/' . $intervalIndex] : 0) + $this->_getValue($value); } else { $result[$intervalIndex] = (array_key_exists($intervalIndex, $result) ? $result[$intervalIndex] : 0) + $this->_getValue($value); } } return $result; }