date_make_date

Versions
5 – 7
date_make_date($date, $timezone = NULL, $type = DATE_DATETIME, $granularity = array('year', 'month', 'day', 'hour', 'minute'))

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. @param $granularity The granularity of the date value provided. Set this for partial dates so they pass validation and don't get reset to 'now'.

▾ 26 functions call date_make_date()

date_combo_validate in contributions/date/date/date_elements.inc
Validate and update a combo element. Don't try this if there were errors before reaching this point.
date_days in contributions/date/date_api.module
An array of days.
date_days_in_month in contributions/date/date_api.module
Identify the number of days in a month for a date.
date_formatter_process in contributions/date/date/date.module
Helper function for creating formatted date arrays from a formatter.
date_ical_date in contributions/date/date_api_ical.inc
Return a date object for the ical date, adjusted to its local timezone.
date_ical_parse_duration in contributions/date/date_api_ical.inc
Parse the duration of the event. Example: DURATION:PT1H30M DURATION:P1Y2M
date_local_date in contributions/date/date/date_elements.inc
Create local date object.
date_now in contributions/date/date_api.module
A date object for the current time.
date_popup_input_value in contributions/date/date_popup/date_popup.module
Helper function for extracting a date value out of user input.
date_popup_process in contributions/date/date_popup/date_popup.module
Javascript popup element processing. Add popup attributes to $element.
date_repeat_build_dates in contributions/date/date/date_repeat.inc
Helper function to build repeating dates from a $node_field.
date_repeat_set_month_day in contributions/date/date_repeat/date_repeat_calc.inc
Set a date object to a specific day of the month.
date_repeat_set_year_day in contributions/date/date_repeat/date_repeat_calc.inc
Set a date object to a specific day of the year.
date_select_process in contributions/date/date_api_elements.inc
Flexible date/time drop-down selector.
date_text_process in contributions/date/date_api_elements.inc
Text date input form.
date_timezone_requirements in contributions/date/date_timezone/date_timezone.install
Implementation of hook_requirements(). Make sure a site timezone name has been selected.
date_timezone_update_site in contributions/date/date_timezone/date_timezone.module
Callback from site timezone settings form to update site timezone info. When the timezone name is updated, update the offset as well.
date_timezone_update_user in contributions/date/date_timezone/date_timezone.module
Callback from user timezone settings form to update user timezone info. When the timezone name is updated, update the offset as well.
date_token_values in contributions/date/date/date_token.inc
date_tools_copy_convert_events in contributions/date/date_tools/date_tools.module
date_week in contributions/date/date_api.module
The calendar week number for a date.
date_weeks_in_year in contributions/date/date_api.module
The number of calendar weeks in a year.
date_week_range in contributions/date/date_api.module
Start and end dates for a calendar week, adjusted to use the chosen first day of week for this site.
_date_content_generate in contributions/date/date/date_content_generate.inc
Implementation of Devel module's hook_content_generate().
_date_repeat_calc in contributions/date/date_repeat/date_repeat_calc.inc
Private implementation of date_repeat_calc().
_date_repeat_rrule_process in contributions/date/date_repeat/date_repeat_form.inc
Generate the repeat setting form.

Code

contributions/date/date_api.module, line 770

<?php
function date_make_date($date, $timezone = NULL, $type = DATE_DATETIME, $granularity = array('year', 'month', 'day', 'hour', 'minute')) {
  // No value or one that can't be used.
  if (empty($date) || is_array($date)) {
    return NULL;
  }

  // Special handling for partial dates that don't need precision.
  $max_granularity = array_pop($granularity);
  if (in_array($max_granularity, array('year', 'month')) || $type == DATE_ISO || $type == DATE_ARRAY) {
    $date = date_fuzzy_datetime($date);
    $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) || !date_timezone_is_valid($timezone)) {
    $timezone = date_default_timezone_name();
  }
  if (!date_is_valid($date, $type, $granularity)) {
    $date = 'now';
  }
  if (!empty($timezone) && !empty($date)) {
    if ($date == 'now') {
      return date_create('now', timezone_open($timezone));
    }
    elseif ($datetime = date_convert($date, $type, DATE_DATETIME, $timezone)) {
      return date_create($datetime, timezone_open($timezone));
    }
  }
  return NULL;
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.