Hi there,
Out of the blue, on a Drupal 6 site that uses the Date module, I get this error when trying to generate programatically some nodes:
date_format() expects parameter 1 to be DateTime, null given in .../date/date/date_elements.inc on line 505
// Neither the from date nor the to date should be empty at this point
// unless they held values that couldn't be evaluated.
if (!$field['required'] && (empty($from_date) || empty($to_date))) {
$item = date_element_empty($element, $form_state);
$errors[] = t('The dates are invalid.');
}
elseif (!empty($field['todate']) && $from_date > $to_date) {
form_set_value($element[$to_field], $to_date, $form_state);
$errors[] = t('The To date must be greater than the From date.');
}
else {
// Convert input dates back to their UTC values and re-format to ISO
// or UNIX instead of the DATETIME format used in element processing.
$timezone = !empty($item[$tz_field]) ? $item[$tz_field] : $element['#date_timezone'];
$timezone_db = date_get_timezone_db($field['tz_handling']);
$item[$tz_field] = $timezone;
$from_date = date_make_date($from_date, $timezone);
$item[$offset_field] = date_offset_get($from_date);
$to_date = date_make_date($to_date, $timezone);
$test_from = date_format($from_date, 'r');
$test_to = date_format($to_date, 'r');
$item[$offset_field2] = date_offset_get($to_date);
date_timezone_set($from_date, timezone_open($timezone_db));
date_timezone_set($to_date, timezone_open($timezone_db));
$item[$from_field] = date_format($from_date, date_type_format($field['type']));
$item[$to_field] = date_format($to_date, date_type_format($field['type'])); <-----THIS IS LINE 505 OF THE ERROR FILE
if (isset($form_values[$field_name]['rrule'])) {
$item['rrule'] = $form_values[$field['field_name']]['rrule'];
}
The thing is that this doesn´t happens every time, but just "sometimes" ina very random way.
As I didn´t change anything in my site since several months, I don´t know where to look for. In my custom module?
I´ve disabled all Calendar modules without any luck.
I know I´m not giving any information, but I don´t know really what information to provide, nor where should I look for it. I´ve search for this error, and all references of it are from several years now, so I´m inclined to understand that all bug references of the past is now solved.
I´ve upgraded to the latest stable version of date, with the same buggy result:
The nodes are not created and this error appears in the log.
Thanks for any insight about this.