public function testParse() { $locale = $this->getContext()->getTranslationManager()->getLocale('@timezone=GMT+0200'); $inputFormat = new AgaviDateFormat('yyyy-MM-dd HH:mm:ss'); $cal = $inputFormat->parse('2008-11-19 23:00:00', $locale, false); $tz = $cal->getTimeZone(); $this->assertEquals('GMT+0200', $tz->getId(), 'Failed asserting that the created timezone is a custom timezone.'); $this->assertTrue($tz instanceof AgaviSimpleTimezone, 'Failed asserting that the created tz is an AgaviSimpleTimezone.'); $this->assertEquals(2 * 60 * 60 * 1000, $tz->getRawOffset(), 'Failed asserting that the timezone has the proper offset.'); }
public function testTicket962() { $ctx = AgaviContext::getInstance(); $tm = $ctx->getTranslationManager(); $locale = $tm->getLocale('de@timezone=America/Los_Angeles'); $inputFormat = new AgaviDateFormat('yyyy-MM-dd HH:mm:ssZZZ'); $cal = $inputFormat->parse('2008-11-19 23:00:00America/Los_Angeles', $locale, false); $originalTimeZoneId = $cal->getTimeZone()->getId(); $this->assertEquals('America/Los_Angeles', $cal->getTimeZone()->getId()); $this->assertEquals('Donnerstag, 20. November 2008 2:00 Uhr GMT-05:00', $tm->_d($cal, null, 'de@timezone=America/New_York')); $this->assertEquals($originalTimeZoneId, $cal->getTimeZone()->getId()); }
/** * Initialize this Translator. * * @param AgaviContext The current application context. * @param array An associative array of initialization parameters * * @author Dominik del Bondio <*****@*****.**> * @author David Zülke <*****@*****.**> * @since 0.11.0 */ public function initialize(AgaviContext $context, array $parameters = array()) { parent::initialize($context, $parameters); $type = 'datetime'; if (isset($parameters['translation_domain'])) { $this->translationDomain = $parameters['translation_domain']; } if (isset($parameters['type']) && in_array($parameters['type'], array('date', 'time'))) { $type = $parameters['type']; } if (isset($parameters['format'])) { $this->customFormat = $parameters['format']; if (is_array($this->customFormat)) { // it's an array, so it contains the translations already, DOMAIN MUST NOT BE SET $this->translationDomain = null; } } $this->type = $type; }
/** * Returns the calendar object for a max or min definition. * * @param string 'min' or 'max' * @param AgaviDateFormat The default format when parsing strings. * @param AgaviLocale The locale to use. * * @return AgaviCalendar The calendar object storing the date. * * @author Dominik del Bondio <*****@*****.**> * @since 0.11.0 */ protected function getMinOrMaxValue($minMax, $defaultParseFormat, $locale) { $format = $defaultParseFormat; $minMax = $this->getParameter($minMax); if (is_array($minMax)) { $minMaxValue = $this->validationParameters->getParameter($minMax['field']); if (!$minMaxValue instanceof AgaviCalendar) { if (isset($minMax['format'])) { $format = new AgaviDateFormat($minMax['format']); } $result = $format->parse($minMaxValue, $locale, false); } else { $result = $minMaxValue; } } elseif (strpos($minMax, '.') === false) { // a strtotime compatible string does not contain a dot, so all strings with dots are assumed to be // strings matching the calendar format and all others are handled with strtotime $tz = $locale->getLocaleTimeZone(); if ($tz) { // set the timezone for the strtotime call to be the same as for creating the calendar $oldDefaultTimezone = date_default_timezone_get(); date_default_timezone_set($tz); } // create the calendar in the requested locale/timezone $result = $this->getContext()->getTranslationManager()->createCalendar($locale); $result->setUnixTimestamp(strtotime($minMax)); if ($tz) { // reset the php timezone date_default_timezone_set($oldDefaultTimezone); } } else { $result = $format->parse($minMax, $locale, false); } return $result; }
/** * Creates a new date format instance with the given format. * * @param string The date format. * * @return AgaviDateFormat The dateformat instance. * * @author Dominik del Bondio <*****@*****.**> * @since 0.11.0 */ public function createDateFormat($format) { $dateFormat = new AgaviDateFormat($format); $dateFormat->initialize($this->getContext()); return $dateFormat; }