You are here

function availability_calendar_parse_entry_date in Availability Calendars 7.5

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

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

Note that when the date popup module is enabled dates are passed in the ISO date format.

Parameters

string $date:

Return value

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

7 calls to availability_calendar_parse_entry_date()
availability_calendar_booking_formlet_extract_date in booking_formlet/availability_calendar_booking_formlet.inc
Returns a date based on the settings and global context.
availability_calendar_handler_filter_availability::fillEmptyValueFromOther in views/availability_calendar_handler_filter_availability.inc
If 1 of the values is empty, try to fill it based on the other value and the (operator) type.
availability_calendar_handler_filter_availability::getValidOrEmptyValue in views/availability_calendar_handler_filter_availability.inc
Returns the given value if it is valid or an empty value otherwise.
availability_calendar_handler_filter_availability::op_from_duration in views/availability_calendar_handler_filter_availability.inc
availability_calendar_handler_filter_availability::op_from_to in views/availability_calendar_handler_filter_availability.inc

... See full list

File

./availability_calendar.inc, line 209

Code

function availability_calendar_parse_entry_date($date) {
  $result = FALSE;
  if (module_exists('date_popup')) {
    $result = availability_calendar_parse_iso_date($date);
  }
  if ($result === FALSE) {
    $date_type = 'availability_calendar_date_entry';
    $format = variable_get("date_format_{$date_type}", AC_DATE_ENTRY);

    // 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;
    }
    if ($result instanceof DateTime) {
      $result
        ->setTime(0, 0, 0);
    }
  }
  return $result;
}