You are here

function date_make_date in Date 6

Same name and namespace in other branches
  1. 5.2 date_api.module \date_make_date()
  2. 5 date.inc \date_make_date()
  3. 6.2 date_api.module \date_make_date()

Convert a date of any type or an array of date parts into a valid date object.

Parameters

$date: A date in any format or the string 'now'. @param $timezone Optional, the name of the timezone this date is in, defaults to the user timezone, if set, otherwise the site timezone. Accepts either a timezone name or a timezone object as input. @param $type The type of date provided, could be DATE_ARRAY, DATE_UNIX, DATE_DATETIME, DATE_ISO, or DATE_OBJECT.

31 calls to date_make_date()
date_api_filter_handler::date_filter in ./date_api.views.inc
date_combo_validate in date/date_elements.inc
Validate and update a combo element. Don't try this if there were errors before reaching this point.
date_convert in ./date_api.module
Date conversion helper function.
date_copy_convert_events in date_copy/date_copy.module
date_data_integrity in date/date.install
Progressive update of date information, integrity checking of all date values.

... See full list

File

./date_api.module, line 551
This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.

Code

function date_make_date($date, $timezone = NULL, $type = DATE_DATETIME) {

  // Make sure some value is set for the date and timezone even if the
  // site timezone is not yet set up to avoid fatal installation
  // errors.
  if (empty($timezone)) {
    $timezone = date_default_timezone_name();
  }
  if (!date_is_valid($date, $type) || empty($date)) {
    $date = 'now';
  }
  if (!empty($timezone) && !empty($date)) {
    if (!is_object($timezone)) {
      $timezone = timezone_open($timezone);
    }
    if ($date == 'now') {
      return date_create('now', $timezone);
    }
    elseif ($datetime = date_convert($date, $type, DATE_DATETIME)) {
      if ($type == DATE_UNIX && timezone_name_get($timezone) != 'UTC') {
        $date = date_create($datetime, timezone_open('UTC'));
        date_timezone_set($date, $timezone);
        return $date;
      }
      else {
        return date_create($datetime, $timezone);
      }
    }
  }
  return NULL;
}