You are here

public function DatexPoorMansGregorianCalendar::validate in Datex 8

Overrides DatexPartialImplementation::validate

File

src/Datex/DatexPoorMansGregorianCalendar.php, line 30
Fallback calendar implementation in case php-intl is not available.

Class

DatexPoorMansGregorianCalendar

Namespace

Drupal\datex\Datex

Code

public function validate(array $arr) {
  if ((!isset($arr['year']) || empty($arr['year'])) && (!isset($arr['month']) || empty($arr['month'])) && (!isset($arr['day']) || empty($arr['day']))) {
    return NULL;
  }
  $zero = TRUE;
  $year = intval($arr['year']);
  $month = intval($arr['month']);
  $day = intval($arr['day']);
  if ($year < 0 || $year === 0 && $zero) {
    return t('Year out of range');
  }
  if ($month < 0 || 12 < $month || $month === 0 && $zero) {
    return t('Month out of range');
  }
  if ($day === 0 && $zero || $day < 0 || 31 < $day) {
    return t('Day out of range');
  }
  return FALSE;
}