/** * Get date * * @param string|integer $date * @param array $options * string type (date or date_unixtime) * string format (full, long, medium, short) * @param string $locale * @return string */ public function __invoke($date, array $options = [], $locale = null) { $type = !empty($options['type']) && $options['type'] == 'date' ? 'date' : 'date_unixtime'; if ($type == 'date_unixtime' && !(int) $date) { return; } $format = isset($options['format']) ? $options['format'] : SettingService::getSetting('application_default_date_format'); $format = strtolower($format); switch ($format) { case 'full': $format = IntlDateFormatter::FULL; break; case 'long': $format = IntlDateFormatter::LONG; break; case 'medium': $format = IntlDateFormatter::MEDIUM; break; case 'short': default: $format = IntlDateFormatter::SHORT; } return LocaleUtility::convertToLocalizedValue($date, $type, $format, $locale); }
/** * Validate the date end * * @param $value * @param array $context * @return boolean */ public function validateDateEnd($value, array $context = []) { // compare the date start and date end if (!empty($context['date_start'])) { return LocalizationLocaleUtility::convertFromLocalizedValue($value, 'date_unixtime') > LocalizationLocaleUtility::convertFromLocalizedValue($context['date_start'], 'date_unixtime'); } return true; }
/** * Set custom locale * * @param string $locale * @return void */ protected function setCustomLocale($locale) { Locale::setDefault($locale); LocaleUtility::setLocale($locale); }
/** * Validate xml map priority * * @param $value * @param array $context * @return boolean */ public function validateXmlMapPriority($value, array $context = []) { $value = (double) LocalizationUtility::convertFromLocalizedValue($value, 'float'); return $value >= 0 && $value <= 1; }
/** * Set data to validate and/or populate elements * * Typically, also passes data on to the composed input filter. * * @param array|\ArrayAccess|Traversable $data * @param boolean $convertValues * @return Form|FormInterface * @throws Zend\Form\Exception\InvalidArgumentException */ public function setData($data, $convertValues = true) { // unset not validated fields foreach ($this->notValidatedElements as $name) { if (isset($data[$name])) { unset($data[$name]); } } // convert localized values if ($convertValues) { foreach ($data as $fieldName => $fieldValue) { if (!isset($this->customElements[$fieldName])) { continue; } $data[$fieldName] = LocaleUtility::convertToLocalizedValue($fieldValue, $this->customElements[$fieldName]); } } return parent::setData($data); }