Download & Extend

date_make_date() returns empty object

Project:Date
Version:6.x-2.2
Component:Date API
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Hi,
I'm not sure if this is a duplicate or not, but i couldnt find anything in the queues to exactly what i was experiencing straight away, sorry if it is.

when i try calling date_make_date() to generate a date object it returns an empty object.

i have tried multiple formats as following -

$date = date_make_date('2009-07-09 12:18:06', null, DATE_DATETIME);

$date = date_make_date('2009-07-09T12:18:06', DATE_ISO);

I have also tried with DATE_ARRAY. All these return a blank object :(

any ideas?

Comments

#1

Passing in an array for $date and a type of DATE_ARRAY would return a NULL according to the code:

<?php
 
if (empty($date) || is_array($date)) {
    return
NULL;
  }
?>

#2

Status:active» closed (works as designed)

It's not 'an empty object', that's the way the PHP date object works. You can't see anything in it, but it is valid. You can do things like:

<?php
print date_format($date, 'm/d/Y H:i');
?>

And you will see that it holds a value.

#3

Status:closed (works as designed)» active

Hi there

I'm encountering the same issue.

Passing in $date as an array, and setting the $type to DATE_ARRAY:

$date = array(
  'year' => 2010,
  'month' => 6,
  'day' => 20,
  'hour' => 12,
  'minute' => 0,
  'second' => 0,
);

$date_object = date_make_date($date, 'Europe/Brussels', DATE_ARRAY);

$date_object is NULL now because of the line mentioned by budda.

Removing the is_array() check seems to solve the problem here.

#4

Status:active» needs review

I suggest just removing the is_array check, I don't see what's the use of it.

#5

A temporary workaround is using date_convert() instead of date_make_date().

$date_object = date_convert($date, DATE_ARRAY, DATE_OBJECT, date_default_timezone_name());

#6

I just noticed the same thing.

Trying to get this to work:

$date = date_make_date('1995-10-09T00:00', NULL, DATE_ISO);

returns me an empty object. I've also tried it with DATE_DATETIME. No dice.

nobody click here