You are here

public function DatexIntlCalendar::parse in Datex 8

Overrides DatexInterface::parse

File

src/Datex/DatexIntlCalendar.php, line 39

Class

DatexIntlCalendar

Namespace

Drupal\datex\Datex

Code

public function parse($value, $format) {
  $pat = static::format2pattern($format);
  $this->intlFormatter
    ->setPattern($pat);
  try {
    $timestamp = $this->intlFormatter
      ->parse($value);
    $timestamp = intval($timestamp);
    $this
      ->setTimestamp($timestamp);
    if ($this
      ->format($format) !== $value) {
      return FALSE;
    }
  } catch (\Exception $e) {
    return FALSE;
  }
  return TRUE;
}