Пример #1
0
 /**
  * Checks if the given value is a valid DateTime object.
  * Note: a value of NULL or empty string ('') is considered valid
  *
  * @param mixed $value The value that should be validated
  * @return void
  * @api
  */
 protected function isValid($value)
 {
     if ($value instanceof \DateTime) {
         return;
     }
     if (!isset($this->options['locale'])) {
         $locale = $this->localizationService->getConfiguration()->getDefaultLocale();
     } elseif (is_string($this->options['locale'])) {
         $locale = new \TYPO3\FLOW3\I18n\Locale($this->options['locale']);
     } elseif ($this->options['locale'] instanceof \TYPO3\FLOW3\I18n\Locale) {
         $locale = $this->options['locale'];
     } else {
         $this->addError('The "locale" option can be only set to string identifier, or Locale object.', 1281454676);
         return;
     }
     if (!isset($this->options['strictMode']) || $this->options['strictMode'] === TRUE) {
         $strictMode = TRUE;
     } else {
         $strictMode = FALSE;
     }
     if (isset($this->options['formatLength'])) {
         $formatLength = $this->options['formatLength'];
         \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::validateFormatLength($formatLength);
     } else {
         $formatLength = \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_LENGTH_DEFAULT;
     }
     if (isset($this->options['formatType'])) {
         $formatType = $this->options['formatType'];
         \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::validateFormatType($formatType);
     } else {
         $formatType = \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_DATE;
     }
     if ($formatType === \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_TIME) {
         if ($this->datetimeParser->parseTime($value, $locale, $formatLength, $strictMode) === FALSE) {
             $this->addError('A valid time is expected.', 1281454830);
         }
     } elseif ($formatType === \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_DATETIME) {
         if ($this->datetimeParser->parseDateAndTime($value, $locale, $formatLength, $strictMode) === FALSE) {
             $this->addError('A valid date and time is expected.', 1281454831);
         }
     } else {
         if ($this->datetimeParser->parseDate($value, $locale, $formatLength, $strictMode) === FALSE) {
             $this->addError('A valid date is expected.', 1281454832);
         }
     }
 }
Пример #2
0
 /**
  * Parses dateTime with format string for date and time defined in CLDR for
  * particular locale.
  *
  * @param string $dateAndTimeToParse Date and time to be parsed
  * @param \TYPO3\FLOW3\I18n\Locale $locale
  * @param string $formatLength One of: full, long, medium, short, or 'default' in order to use default length from CLDR
  * @param boolean $strictMode Work mode (strict when TRUE, lenient when FALSE)
  * @return mixed Array of parsed date and time elements, FALSE on failure
  */
 public function parseDateAndTime($dateAndTimeToParse, \TYPO3\FLOW3\I18n\Locale $locale, $formatLength = \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_LENGTH_DEFAULT, $strictMode = TRUE)
 {
     \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::validateFormatLength($formatLength);
     return $this->doParsingWithParsedFormat($dateAndTimeToParse, $this->datesReader->parseFormatFromCldr($locale, \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_DATETIME, $formatLength), $this->datesReader->getLocalizedLiteralsForLocale($locale), $strictMode);
 }
Пример #3
0
 /**
  * Formats dateTime with format string for date and time defined in CLDR for
  * particular locale.
  *
  * First date and time are formatted separately, and then dateTime format
  * from CLDR is used to place date and time in correct order.
  *
  * @param \DateTime $dateTime PHP object representing particular point in time
  * @param \TYPO3\FLOW3\I18n\Locale $locale
  * @param string $formatLength One of DatesReader FORMAT_LENGTH constants
  * @return string Formatted date and time
  * @api
  */
 public function formatDateTime(\DateTime $dateTime, \TYPO3\FLOW3\I18n\Locale $locale, $formatLength = \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_LENGTH_DEFAULT)
 {
     \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::validateFormatLength($formatLength);
     return $this->doFormattingWithParsedFormat($dateTime, $this->datesReader->parseFormatFromCldr($locale, \TYPO3\FLOW3\I18n\Cldr\Reader\DatesReader::FORMAT_TYPE_DATETIME, $formatLength), $this->datesReader->getLocalizedLiteralsForLocale($locale));
 }