You are here

function _datex_popup_parse in Datex 7.3

Parse date string.

1 call to _datex_popup_parse()
_datex_date_popup_field_element_validate_callback in datex_popup/datex_popup.module
Form element validation callback for date popup form element.

File

datex_popup/datex_popup.module, line 108

Code

function _datex_popup_parse(DatexInterface $calendar, $value, $g) {

  // Somebody please, give this man a regex.
  if (!is_string($value)) {
    return NULL;
  }
  $value = trim($value);

  // Replace, just to make sure.
  $date = explode('/', str_replace('\\', '/', $value));
  if (empty($date)) {
    return NULL;
  }
  foreach ($date as $granul) {
    if (intval($granul) === 0) {
      return NULL;
    }
  }
  $has_day = in_array('day', $g, TRUE);
  $has_month = in_array('month', $g, TRUE);
  if ($has_day && count($date) < 3 || $has_month && count($date) < 2) {
    return NULL;
  }
  $year = (int) $date[0];
  $month = $has_month ? (int) $date[1] : 6;
  $day = $has_day ? (int) $date[2] : 25;
  $calendar
    ->setDateLocale($year, $month, $day);
  return TRUE;
}