date_make_date
- 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'.
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')) {
if (empty($date) || is_array($date)) {
return NULL;
}
$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;
}
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;
}
?>