/** * Populates calendar's month names from translation list and caches them. * * @param array $format * @return array */ public function getMonthNames(array $format = array()) { if (empty($this->_monthNames)) { $months = Zend_Locale::getTranslationList('month', $this->_date->getLocale(), $format); foreach ($months as $month) { $this->_monthNames[] = $month; } } return $this->_monthNames; }
/** * Prepare given time to fit the first timestamp of given intervall. * * E.g. INTERVALL_TYPE_MONTH, '2011-01-12 10:06:23' => '2011-01-01 00:00:00' * * Filter date if not in usable range: * too early => set datetime to first flattened datetime value of measured data * in range => ok * too late => set datetime to last datetime value of measured data * AND call this method recursively for flattening this datetime to e.g. Monday 00:00 * * @param Diagram_Model_IntervallMapper::INTERVALL_TYPE_* $intervallType * @param string|timestamp|Zend_Date $intervallStart * @return Zend_Date */ public static function getPreparedStartDate($intervallType, $intervallStart) { /* @var $date Zend_Date */ $date = null; if ($intervallStart instanceof Zend_Date) { $date = clone $intervallStart; } else { $date = new Zend_Date($intervallStart); } if ($date->isEarlier(self::getFirstMeasurementDate())) { $firstStartDate = new Zend_Date(self::getFirstMeasurementDate(), null, $date->getLocale()); $date = self::getPreparedStartDate($intervallType, $firstStartDate); } elseif ($date->isLater(self::getLastMeasurementDate())) { $lastEndDate = new Zend_Date(self::getLastMeasurementDate(), null, $date->getLocale()); $date = self::getPreparedStartDate($intervallType, $lastEndDate); } switch ($intervallType) { case self::INTERVALL_TYPE_YEAR: $date->setMonth(1); case self::INTERVALL_TYPE_MONTH: $date->setDay(1); case self::INTERVALL_TYPE_DAY: $date->setHour(0); case self::INTERVALL_TYPE_HOUR: $date->setMinute(0); $date->setSecond(0); break; // Doesn't fit with the others. Therefore handle separately. // Doesn't fit with the others. Therefore handle separately. case self::INTERVALL_TYPE_WEEK: // 1 == monday $date->setWeekday(1); $date->setHour(0); $date->setMinute(0); $date->setSecond(0); } return $date; }
/** * Test for ZF-3677 */ public function testZF3677() { $locale = new Zend_Locale('de_AT'); require_once 'Zend/Registry.php'; Zend_Registry::set('Zend_Locale', $locale); $date = new Zend_Date('13', null, $locale); $this->assertSame($date->getLocale(), $locale->toString()); }
/** * test setLocale/getLocale */ public function testSetLocale() { $date = new Zend_Date(0, 'de'); $this->assertSame($date->getLocale(), 'de'); $date->setLocale('en'); $this->assertSame($date->getLocale(), 'en'); $date->setLocale('en_XX'); $this->assertSame($date->getLocale(), 'en'); $date->setLocale('de_AT'); $this->assertSame($date->getLocale(), 'de_AT'); $locale = new Zend_Locale('ar'); $date->setLocale($locale); $this->assertSame($date->getLocale(), 'ar'); try { $date->setLocale('xx_XX'); $this->fail(); } catch (Zend_Date_Exception $e) { // success } }
/** * Test accessors for _Locale member property of Zend_Date */ public function testLocale() { $date = new Zend_Date(Zend_Date::now()); $locale = new Zend_Locale('en_Us'); $set = $date->setLocale($locale); $this->assertSame($date->getLocale(), $set); }
public static function datetime($timestamp, $part = null) { $date = new Zend_Date($timestamp, $part); $locale = $date->getLocale(); return $date->toString(Zend_Locale_Data::getContent($locale, 'date', 'medium') . ' ' . Zend_Locale_Data::getContent($locale, 'time', 'short')); }