| Project: | Date |
| Version: | 6.x-2.7 |
| Component: | Date API |
| Category: | bug report |
| Priority: | major |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
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:
<?php
$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', );
?>
Comments
#1
subscribing
#2
+1 similar unknown problem :S
#3
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
#4
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...
#5
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.
#6
This patch works fine for me, thanks.
#7
@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.
#8
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.
#9
Thanks for testing, Spark_man. What version of PHP are you using? I tried with PHP 5.2 and the patches both worked fine.
#10
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!
#11
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
#12
subscribing
#13
sub
#14
The patch referenced in #10 seems to have done the trick for me.
#15
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.
#16
Patch in #10 worked for me.
#17
patch works for me.
#18
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
#19
subscribing
#20
Patch #10 works for me on PHP 5.2.6-1+lenny8.
#21
Subscribing
#22
subscribing
#23
* 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.
#24
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.
#25
Subscribing
#26
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...
#27
Patch #10 works (Windows 7, PHP 5.2.9-2, Apache 2.2.11). Thank you.
#28
I applied both patches and warnings cleared. Drupal 6.17 on PHP 5.2
#29
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.
#30
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
#31
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)
#32
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?
#33
#34
subscribe
#35
The attached patch in #5 worked for me. Running Drupal 7.0-alpha5.
#36
I also had to apply patches from #5 and #10 for all warnings to disappear on my PHP 5.3.2 box
#37
Patch at #5 stopped the errors I was seeing
#38
Patch at #5 works for me too.
#39
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.
#40
Patches 5 and 10 did it for me. They do work
#41
#5 works for me using PHP 5.2.6
+1
#42
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.
#43
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
<?phpIndex: 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':
?>
#44
In regard to comment #42, greta_drupal has a good point, were the patches applied to the new July 11, 2010 dev version? thanks.
#45
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.
#46
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
#47
I can tell you that they were not.
#48
Applied #5 and #10 and my errors are gone now.
Please Commit this.
Thanks!
#49
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!
#50
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#51
tyty! applying patches 518816 and date-772180-element-description removed the warning
#52
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.
#53
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
#54
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.
#55
subscribe
#56
Applied both patches and the problem appears resolved, cheers.
date-772180-element-description-1.patch
518816-5.date_format_date_warnings.patch
#57
Subscribing....
#58
Subscribing
#59
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.
#60
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.
#61
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.
#62
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.
#63
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?
#64
The changes were first released in date 6.x-2.5, and are still present in 6.x-2.6.
#65
Excellent! many thanks all.
#66
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!
#67
Automatically closed -- issue fixed for 2 weeks with no activity.
#68
I have this error on 6.27.
#69
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.
#70
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
#71
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).
#72
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).
#73
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
#74
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??????????????
#75
Hi seethav, please post your question in the forum.
#76
in my case i used 'now -1hr' it should be 'now -1hour'. sometimes it's the little things. And spacing does matter.