You are here

public function DateArgumentWrapper::validateValue in Calendar 8

Check if a string value is valid for this format.

\DateTime::createFromFormat will not throw an error but try to make a date \DateTime::getLastErrors() is also not reliable.

Parameters

string $value:

Return value

bool

1 call to DateArgumentWrapper::validateValue()
DateArgumentWrapper::createDateTime in src/DateArgumentWrapper.php

File

src/DateArgumentWrapper.php, line 232

Class

DateArgumentWrapper
The DateArgumentWrapper class.

Namespace

Drupal\calendar

Code

public function validateValue() {
  $value = $this->dateArg
    ->getValue();
  if (empty($value)) {
    return FALSE;
  }
  if ($this
    ->getArgFormat() == 'oW') {
    $info = $this
      ->getYearWeek($value);

    // Find the max week for a year. Some years start a 53rd week.
    $max_week = gmdate("W", strtotime("28 December {$info['year']}"));
    return $info['week'] >= 1 && $info['week'] <= $max_week;
  }
  else {
    $created_date = $this
      ->createFromFormat($value);
    return $created_date && $created_date
      ->format($this
      ->getArgFormat()) == $value;
  }
}