public function DatexObject::xobjectFromDate in Datex 7.2
Creates a DateTime object containing date extracted from $date.
2 calls to DatexObject::xobjectFromDate()
- DatexObject::objectFromDate in datex_api/
datex_api.class.inc - Created datex object from a localized date.
- DatexObject::xsetDatetime in datex_api/
datex_api.class.inc - Set date-time of object instance by extracting timestamp from given date.
File
- datex_api/
datex_api.class.inc, line 565 - Provides an API to work with dates.
Class
- DatexObject
- Base class for localized DateTime.
Code
public function xobjectFromDate($date = NULL, $tz = NULL) {
if (is_object($date)) {
$date = clone $date;
}
else {
if (is_numeric($date)) {
$date = '@' . $date;
}
elseif (is_array($date)) {
$now = getdate();
$year = isset($date['year']) ? intval($date['year']) : $now['year'];
$month = isset($date['month']) ? intval($date['month']) : $now['mon'];
$day = isset($date['day']) ? intval($date['day']) : $now['mday'];
$hour = isset($date['hour']) ? intval($date['hour']) : $now['hours'];
$minute = isset($date['minute']) ? intval($date['minute']) : $now['minutes'];
$second = isset($date['second']) ? intval($date['second']) : $now['seconds'];
$date = '@' . mktime($hour, $minute, $second, $month, $day, $year);
}
elseif ($date == NULL) {
$date = 'now';
}
$date = new DateTime($date);
}
// For anyone reading this comment: Passing a DateTimeZone to datetime
// constructor has no effect on it! You MUST use setTimezone to set a
// tz on the stupid object.
// Tested on PHP 5.4.15 (built: May 12 2013 13:11:23) Archlinux.
if (isset($tz)) {
$tz = $this
->getTzObject($tz);
$date
->setTimeZone($tz);
}
return $date;
}