I have created a new content type with a Date CCK field.
When I create or edit a node of this content type, and save or preview, then I get these errors:

* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/sites/all/modules/date/date/date.module on line 355.
* warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /var/www/sites/all/modules/date/date/date.module on line 357.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/sites/all/modules/date/date/date.module on line 359.
* warning: date_offset_get() expects parameter 1 to be DateTime, null given in /var/www/sites/all/modules/date/date/date.module on line 361.

Otherwise it seems to work ok.
Currently I don't use the date field yet for a calendar or anything. I just use the tokens for pathauto. Which doesn't run when I preview an edit anyway.

Drupal version: 6.13
Updated Date module to latest version and followed troubleshooting instructions on http://drupal.org/project/date
Using PHP5

Export of my custom content type:

$content['type'] = array ( 'name' => 'Foutparkeerder', 'type' => 'foutparkeerder', 'description' => 'Heb je een foutparkeerder gespot? Meld het hier. Je kan foto\'s meesturen, en op een kaartje aanduiden waar je de foutparkeerder gezien hebt. Zet er ook een beetje uitleg bij over wat er verkeerd of gevaarlijk is aan de verkeerssituatie. Wij kijken je inzending na en zorgen er voor dat die zo snel mogelijk op de voorpagina verschijnt.', 'title_label' => 'Titel', 'body_label' => 'Berichttekst', 'min_word_count' => '10', 'help' => '

Geef een korte beschrijving van de situatie.

', 'node_options' => array ( 'promote' => true, 'status' => false, 'sticky' => false, 'revision' => false, ), 'language_content_type' => '0', 'upload' => '0', 'old_type' => 'foutparkeerder', 'orig_type' => '', 'module' => 'node', 'custom' => '1', 'modified' => '1', 'locked' => '0', 'comment' => '2', 'comment_default_mode' => '4', 'comment_default_order' => '2', 'comment_default_per_page' => '50', 'comment_controls' => '3', 'comment_anonymous' => '2', 'comment_subject_field' => '1', 'comment_preview' => '1', 'comment_form_location' => '1', ); $content['fields'] = array ( 0 => array ( 'label' => 'Tijdstip', 'field_name' => 'field_datetime', 'type' => 'datetime', 'widget_type' => 'date_popup', 'change' => 'Change basic information', 'weight' => '-2', 'default_value' => 'now', 'default_value2' => 'same', 'default_value_code' => '', 'default_value_code2' => '', 'input_format' => 'd/m/Y - H:i', 'input_format_custom' => '', 'year_range' => '-100:+0', 'increment' => '5', 'advanced' => array ( 'label_position' => 'above', 'text_parts' => array ( 'year' => 0, 'month' => 0, 'day' => 0, 'hour' => 0, 'minute' => 0, 'second' => 0, ), ), 'label_position' => 'above', 'text_parts' => array ( ), 'description' => 'Wanneer heb je de foto genomen?', 'required' => 1, 'multiple' => '0', 'repeat' => 0, 'todate' => '', 'granularity' => array ( 'year' => 'year', 'month' => 'month', 'day' => 'day', 'hour' => 'hour', 'minute' => 'minute', ), 'default_format' => 'foutparkeerder_datetime', 'tz_handling' => 'site', 'timezone_db' => 'UTC', 'op' => 'Veldinstellingen indienen', 'module' => 'date', 'widget_module' => 'date', 'columns' => array ( 'value' => array ( 'type' => 'datetime', 'not null' => false, 'sortable' => true, 'views' => true, ), ), 'display_settings' => array ( 'weight' => '-2', 'parent' => '', 'label' => array ( 'format' => 'above', ), 'teaser' => array ( 'format' => 'hidden', 'exclude' => 0, ), 'full' => array ( 'format' => 'default', 'exclude' => 0, ), 4 => array ( 'format' => 'default', 'exclude' => 0, ), 2 => array ( 'format' => 'default', 'exclude' => 0, ), 3 => array ( 'format' => 'default', 'exclude' => 0, ), 'token' => array ( 'format' => 'default', 'exclude' => 0, ), ), ), ); $content['extra'] = array ( 'title' => '-5', 'body_field' => '1', 'menu' => '-3', 'taxonomy' => '-4', 'attachments' => '2', );
CommentFileSizeAuthor
#5 518816-5.date_format_date_warnings.patch606 bytesdww

Comments

patricio.keilty’s picture

subscribing

Rosamunda’s picture

+1 similar unknown problem :S

knightnet’s picture

Same here.

One thought though - is this a PHP 5.3 type issue? I am using a development environment using Uniform Server on Windows - I notice that there are other issues related to differences between PHP 5.2 and 5.3

dww’s picture

Status: Active » Reviewed & tested by the community

User recrit over at #772180-16: "date_format() expects parameter 1 to be DateTime, string given" warnings when creating/editing nodes with date fields posted date-772180-element-description-1.patch which myself and many others have confirmed is a working solution to this problem. This was the oldest issue open I found about the bug, so I'm consolidating everything into here to clean up the issue queue a bit...

dww’s picture

Component: Date CCK Field » Date API
StatusFileSize
new606 bytes

Also note, user jurgenhaas posted a different solution to the same problem at #798772: Call of date_format requires param 1 to be DateTime, String given. The same patch applies to D6 and is possibly a better solution to the bug here -- inside date_format_date() itself, if the input is a string, convert it to a DateTime object right there. I'll leave it to KarenS to decide which one to commit. There's no real harm in committing both, in fact. I re-rolled the #798772 patch to be more properly formatted and am attaching here for comparison with date-772180-element-description-1.patch.

jurgenhaas’s picture

This patch works fine for me, thanks.

recrit’s picture

@dww - I agree that both patches date-772180-element-description-1.patch and #518816 would be a complete solution since mine only addresses bad calls to date_format() from the date module and 518816 patch catches any calls from any module. 772180 should still get committed so that the date module uses its own functions correctly.

Spark_man’s picture

I have applied the latest patch (518816-5.date_format_date_warnings.patch) and running the latest dev version of Date (6.x-2.x-dev (2010-May-01)) is still giving me:

warning: get_class() expects parameter 1 to be object, string given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal-6.16\sites\all\modules\date\date_api.module on line 651.

dww’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for testing, Spark_man. What version of PHP are you using? I tried with PHP 5.2 and the patches both worked fine.

Spark_man’s picture

PHP Version 5.3.2

BTW: Looked at this thread with fresh eyes this morning and also applied date-772180-element-description-1.patch and that cleared up the problem. Sorry for not reading more closely. It occurs to me that there should be a better way of figuring out which patches to apply to resolve a problem, but then again ... READING is good too! Thanks!

recrit’s picture

it appears the catch all patch 518816-5.date_format_date_warnings.patch will run into this problem for PHP 5.3.0 as stated below from a comment on the PHP manual page

http://us.php.net/manual/en/function.get-class.php

Tom Brown
17-Sep-2009 06:02
As of 5.3.0 this function seems to have started throwing an E_WARNING error if you pass it a non-object. Supress that with "@" if you are actually checking and handling the false return code.

likewhoa’s picture

subscribing

xkater’s picture

sub

adamo’s picture

The patch referenced in #10 seems to have done the trick for me.

mariafromatoz’s picture

Excellent! Patch 5 worked for me for PHP 5.2 and PHP 5.3 and patch 10 sorted the extra warnings for PHP 5.3.

Ta.

bkno’s picture

Patch in #10 worked for me.

likewhoa’s picture

patch works for me.

dww’s picture

If you're going to comment here saying "works for me", please be specific about two things:

1) exactly what patch you tried
2) what version of PHP your site is using

Thanks,
-Derek

rolfmeijer’s picture

subscribing

larskleiner’s picture

Patch #10 works for me on PHP 5.2.6-1+lenny8.

butler360’s picture

Subscribing

jared12’s picture

subscribing

bibo’s picture

* I applied both patches in #5 (or lets say the other was in #10)
* Platform used is Apache/2.2.8 (Ubuntu) PHP/5.2.12 mod_ssl/2.2.8 OpenSSL/0.9.8g (Zend Server)
==> The issues seem to have been fixed. Thanks.

I'd like to set this to "reviewed and tested by the community", but since dww is handling this, I'll just leave it as it is :)

On a sidenote, I'm wondering why critical date-module patches like this don't make it to the module faster. I know people are busy, but there are so many committers to the module.

Offlein’s picture

Patched with Both #5 and #10 .. (Is that right?) on PHP 5.2.6.
The errors when creating a content with a date field were gone with #5. It just seemed like I should see if #10 broke anything even though I wasn't having Spark_Man's problem from #8. It doesn't appear to have had a negative reaction.

danny englander’s picture

Subscribing

giorgio79’s picture

Just tried #5 and got this on a node creation screen with date field:

warning: get_class() expects parameter 1 to be object, string given in ...\date\date_api.module on line 651.

PS:

Notice #10 had the same and the patch there fixed this too...

AndyThornton’s picture

Patch #10 works (Windows 7, PHP 5.2.9-2, Apache 2.2.11). Thank you.

mnzaki’s picture

I applied both patches and warnings cleared. Drupal 6.17 on PHP 5.2

jmiccolis’s picture

Status: Needs work » Needs review

I've tested date-772180-element-description-1.patch on php 5.3. To me that patch looks like the way to go. Either way however, these patches look good.

tdimg’s picture

both patches mentioned in #5 applied individually remove the errors from node/add for me.

my config:
Date 6.x-2.x-dev (2010-May-02)
PHP 5.2.10
CCK Datetime Field with Popup

darrellduane’s picture

I've applied patches #5 and #10 listed above with PHP 5.3.2 (php-5.3.2-2.fc13.x86_64) and the errors have disappeared. Date 6.x-2.x-dev (2010-May-02)

danny englander’s picture

Just curious when an updated version might be coming out that incorporates the patches. I'm deciding do I patch 5 different sites or wait for an update?

giorgio79’s picture

Status: Needs review » Reviewed & tested by the community
emilyf’s picture

subscribe

kaynen’s picture

The attached patch in #5 worked for me. Running Drupal 7.0-alpha5.

deadman’s picture

I also had to apply patches from #5 and #10 for all warnings to disappear on my PHP 5.3.2 box

Screenack’s picture

Patch at #5 stopped the errors I was seeing

Patrick Nelson’s picture

Patch at #5 works for me too.

basvredeling’s picture

I had to apply patches #5 and #10 to fix the description on the date popup widget and the error messages. Works fine now. The errors were present on php 5.2.12.

Carlos Miranda Levy’s picture

Patches 5 and 10 did it for me. They do work

kmonty’s picture

#5 works for me using PHP 5.2.6

+1

greta_drupal’s picture

I don't mean to sound ungrateful, but how is it that this known-for-some-time error (with quick code fix) was not applied to the July 11, 2010 dev version?

Guess it is job security for me, as my client had planned to do updates herself (having never done them before). She'd have been panicked to have hit these errors.

But, in any case, it would have been nice not to have had to hunt down this error and apply the patch....especially since I expected this very fresh version to have included known bug fixes.

So, thanks for the handy mod, no matter.

eric.chenchao’s picture

My PHP version is 5.3.2

When I used #5 patch and I met the get_class warning message like #8

So I changed it like following and for the time being it works for me. Thanks

Index: date_api.module
===================================================================
RCS file: /Users/wright/drupal/local_repo/contributions/modules/date/date_api.module,v
@@ -648,6 +648,9 @@ function date_format_date($date, $type =
   if (empty($date)) {
     return '';
   }
++  if (!is_object($date)) {
++    $date = new DateTime($date);
++  }
   switch ($type) {
     case 'small':
     case 'short':
danny englander’s picture

In regard to comment #42, greta_drupal has a good point, were the patches applied to the new July 11, 2010 dev version? thanks.

mark trapp’s picture

I believe the development snapshots for many modules were regenerated wholesale on July 11th. Many of the dev branch modules I use had an update on July 11th with no apparent changes, and the last time CVS was updated for Date was May 1st, 2010.

mustanggb’s picture

518816-5.date_format_date_warnings.patch on it's own gives #8 warning on PHP 5.3.2
(For me it actually WSOD before commenting out "$date = new DateTime($date);")

date-772180-element-description-1.patch on it's own fixes the issue

Both patches together works fine
However "$date = new DateTime($date);" is never actually called and I worry that is will WSOD again if it ever runs

Please commit date-772180-element-description-1.patch
And possibly a fixed 518816-5.date_format_date_warnings.patch e.g. take a look at #42 or similar solution to the WSOD issue

greta_drupal’s picture

I can tell you that they were not.

bendiy’s picture

Applied #5 and #10 and my errors are gone now.

Please Commit this.

Thanks!

lunk rat’s picture

I am noob when it comes to patching files in subdirectories. #10 seems to move into a date_popup directory. Patching on OSX, how do I tell it to look there. Thanks!

lunk rat’s picture

duh.

If you are patching core then remember to patch from the drupal root directory and use the -p0 parameter to patch. This will stop patch from asking you which file you wish to patch:

$ patch -p0 < example.patch
marina_v’s picture

tyty! applying patches 518816 and date-772180-element-description removed the warning

webchick’s picture

Priority: Normal » Major

I applied #5 to the 7.x-1.x release, and it seems to both apply fine with an offset, and also solve the problem (and also clear up some notices in the process). I'm on PHP 5.2.13 here (MAMP 1.9)

I'm going to escalate the priority of this issue to major, as it's pretty bad for the page to be spouting warnings at you, even if it's otherwise working fine.

deng17’s picture

Why do I still have this warning:
warning: get_class() expects parameter 1 to be object, string given in /home/etherune/public_html/bits/sites/all/modules/date/date_api.module on line 651.

I've already applied patch #5 and #10

gooddesignusa’s picture

I applied patch from #5 and patch from #10 to 6.x-2.x-dev (2010-Jul-11) which seemed to worked for me. Errors are no longer showing up when creating a new date content type.
Platform used is PHP 5.2.13 Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 mod_fcgid/2.3.5

Thanks for everyone's hard work.

zoltán balogh’s picture

subscribe

imclean’s picture

Applied both patches and the problem appears resolved, cheers.

date-772180-element-description-1.patch
518816-5.date_format_date_warnings.patch

myxelf’s picture

Subscribing....

ethnovode’s picture

Subscribing

karens’s picture

Status: Reviewed & tested by the community » Fixed

Both fixes are committed. I lost the issue with the patch for the format descriptions because it got marked as a duplicate, but I found and fixed both things. Sorry for the slow response, and thanks for the patches.

Also much thanks to dww for getting on IRC with me to hash out the best solution.

dww’s picture

Yay, thanks KarenS! Sorry I didn't have time to commit these for you -- it's been a busy few days for me. Just glad to see this finally resolved.

ypogue’s picture

Please correct me if I am wrong, but it was stated that the two patches discussed in this thread (see http://drupal.org/node/518816#comment-3225110) were committed to the dev branch. However, when I updated to 6.x-2.x-dev (Aug. 13) version it was not there. I had to re-apply the patches onto date. Can someone please make sure these patches are applied to the future versions. It will be a big help.

karens’s picture

They are there. If you are getting your code from a tarball, the tarball is only updated twice a day. There are a ton of changes not yet in the tarball.

basvredeling’s picture

Are these commits present in the 2.6 release? Or is the dev from Aug 14 not identical to the 2.6 stable from Aug 14?

dww’s picture

The changes were first released in date 6.x-2.5, and are still present in 6.x-2.6.

basvredeling’s picture

Excellent! many thanks all.

dspring0021’s picture

Ugh...I'm still getting this in 6.x-2.6, but it's only when I call date_format_date() directly from my own PHP code snippet. The date does get formatted, but I get this ugly error printed to the page a few times.

*** UPDATE ***
Nevermind...I wasn't calling date_make_date() first to create the object. D'oh!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sonicthoughts’s picture

Version: 6.x-2.x-dev » 6.x-2.7

I have this error on 6.27.

calefilm’s picture

recently updated to 6x dev. Is my problem related to this issue (DATE) or with the FullCalendar module?

I get this error with the fullcalendar.module:

warning: date_format() expects parameter 1 to be DateTime, null given in /Users/Cale/Sites/acquia-drupal/sites/all/modules/fullcalendar/fullcalendar.module on line 320.

319  $attributes['index'] = $index;
320  $attributes['start'] = date_format($attributes['start'], DATE_FORMAT_DATETIME);
321  $attributes['end'] = date_format($attributes['end'], DATE_FORMAT_DATETIME);
322
323  return l($text, $node->url, array('attributes' => $attributes));
}

And the date disappears (along with To and From time) when I click "add another item" in the node add forms (ANY date form). This is only happening when I have a 'From and To' date option selected... is this a separate issue or related to this issue.... Thanks.

UPDATES:

ERROR UPDATE: took care of this error at http://drupal.org/node/1039140 (#5)
DATE DISAPPEARING UPDATE: Took care of this by going back to DATE 6.x.-2.7. Can now add more date items without problems.

bloke_zero’s picture

I get something similar:

Warning: date_format() expects parameter 1 to be DateTime, boolean given in sites/all/modules/date/includes/date_api_filter_handler.inc on line 325

Date 6.x-2.7 / PHP 5.2.13 - goes away when I switch to PHP 5.3.2

vegemite4me’s picture

If someone else encounters this error message and find that none of the patches help, then have a look at your views. I encountered this error message but it was due to the "Date default" value for a view's filter on a date field. I was using a relative value of "now - 1". It should have been "now -1" (no space between the dash and the number).

Als’s picture

Right said #71.
Actually this check should be done *before* applying any patch.
I have a similar case: the default value for the exposed date field was set as "< now >" insted of "now" (both without double quotes).

ledom’s picture

No errors with php 5.3 but I must go reverse to 5.2 and then this error starts.

#71 works for me
I was using "first day of this month" and "today" as relative date
Clearing relative dates solve the problem without any patch.

Thank you vegemite4me

seethav’s picture

HI

I very new to drupal.I am created one table using data table module and then i created report page using views.In my report page i am displaying date and time in '2011-06-08 11:20:47' but i want to display in report page link 'day-monthname-year'(08-jun-2011).

How to do this? Help me if any one know this??????????????

rolfmeijer’s picture

Hi seethav, please post your question in the forum.

socialnicheguru’s picture

in my case i used 'now -1hr' it should be 'now -1hour'. sometimes it's the little things. And spacing does matter.