You are here

function availability_calendar_parse_display_date in Availability Calendars 7.5

Same name and namespace in other branches
  1. 7.3 availability_calendar.inc \availability_calendar_parse_display_date()
  2. 7.4 availability_calendar.inc \availability_calendar_parse_display_date()

Parses a date string according to the - possibly localized - 'Availability Calendar date display' date type.

Parameters

string $date:

Return value

DateTime|false A DateTime object if the date string could successfully be parsed, false otherwise.

File

./availability_calendar.inc, line 185

Code

function availability_calendar_parse_display_date($date) {
  $date_type = 'availability_calendar_date_display';
  $format = variable_get("date_format_{$date_type}", AC_DATE_DISPLAY);

  // Date API works in PHP5.2, DateTime::createFromFormat in PHP >= 5.3.
  $result = module_exists('date_api') ? new DateObject($date, NULL, $format) : DateTime::createFromFormat($format, $date);
  if ($result instanceof DateObject && !empty($result->errors)) {
    $result = FALSE;
  }
  return $result;
}