You are here

public function CalendarSystemsIntlCalendar::parse in Calendar Systems 8.3

Overrides CalendarSystemsInterface::parse

File

src/CalendarSystems/CalendarSystemsIntlCalendar.php, line 113

Class

CalendarSystemsIntlCalendar

Namespace

Drupal\calendar_systems\CalendarSystems

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;
}