You are here

public function CalendarSystemsPoorMansGregorianCalendar::validate in Calendar Systems 8.3

Overrides CalendarSystemsPartialImplementation::validate

File

src/CalendarSystems/CalendarSystemsPoorMansGregorianCalendar.php, line 32
Fallback calendar implementation in case php-intl is not available.

Class

CalendarSystemsPoorMansGregorianCalendar

Namespace

Drupal\calendar_systems\CalendarSystems

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