Hello, we recently installed the 5.x-2.0-rc calendar on a development site. There is an error message showing up above the calendar, viewable at http://pricold.sundaysenergy.org/calendar

The warning is:

warning: date_create() expects parameter 2 to be DateTimeZone, string given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 576.
warning: date_format() expects parameter 1 to be DateTime, boolean given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 577.
warning: date_create() expects parameter 2 to be DateTimeZone, string given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 578.
warning: date_format() expects parameter 1 to be DateTime, boolean given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 579.
warning: date_create() expects parameter 2 to be DateTimeZone, string given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 576.
warning: date_format() expects parameter 1 to be DateTime, boolean given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 577.
warning: date_create() expects parameter 2 to be DateTimeZone, string given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 578.
warning: date_format() expects parameter 1 to be DateTime, boolean given in /home/ecogard/public_html/sites/all/modules/calendar/calendar.inc on line 579.

I'm wondering why this is and what can be done about it.

Thanks for your help,

Jim

Comments

hhg’s picture

I see the same warnings running on PHP 5.2.5. On PHP 4.3.11 it works.
As the warning says, the date_create takes a DateTimeZone as parameter 2, but the date_php4.inc emulation code states:
@param string $timezone
* PHP 5 uses a timezone object, in PHP 4 use a timezone name.

So the solutions could be a thin timezone object in the date_php4 emulation code, so the date_create function gets the same signature regardless of PHP version

geek-merlin’s picture

same problem here. subscribing.

geek-merlin’s picture

Title: Strange Error Message » date_create() expects parameter 2 to be DateTimeZone, string given

i get these errors when i display a calendar block showing event.module events.

here's the problem code (same as in HEAD)

<?php
              $date = date_create('@'. $values[0], 'UTC');
              $values[0] = date_format($date, DATE_FORMAT_DATETIME);
              $date = date_create('@'. $values[1], 'UTC');
              $values[1] = date_format($date, DATE_FORMAT_DATETIME);
?>

changing both occurences of 'UTC' to new DateTimeZone('UTC') according to the spec makes the errors go away here.

geek-merlin’s picture

Status: Active » Needs review

...but after that i get new errors.

# warning: date_timezone_set() expects parameter 2 to be DateTimeZone, null given in /www/htdocs/konzep/z/sites/all/modules/calendar/calendar.inc on line 628.
# warning: date_timezone_set() expects parameter 2 to be DateTimeZone, null given in /www/htdocs/konzep/z/sites/all/modules/calendar/calendar.inc on line 629.

the offending codeblock is:

<?php
                  $timezone = calendar_event_timezone($node->event_timezone);
                  date_timezone_set($node->calendar_start_date, $timezone);
                  date_timezone_set($node->calendar_end_date, $timezone);
?>

some debugging tells me there are actually 2 different bugs here. see also: #239059: Timezone map in date_php4_tz_map.inc probably wrong

solution: change $timezone to new DateTimeZone($timezone)

after changing this (2 lines in #3, 2 lines in #4) everything works here for me.

webmasterkai’s picture

StatusFileSize
new1.52 KB

Thanks for the help. It works for me. I've attached a patch.

bcn’s picture

subscribing...

johnalbin’s picture

Version: 5.x-2.0-rc » 5.x-2.x-dev
StatusFileSize
new1.6 KB

The patch in #5 is reversed. Also we should be using timezone_open() instead of new DateTimeZone in order to keep compatibility with date_php4.module.

Here’s the correct patch.

johnalbin’s picture

Assigned: jimmb » Unassigned
bcn’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #7 applies and seems to fix the bug (ie the warning are gone).
btw, I'm on PHP 5

kimadactyl’s picture

Patch #7 works for me! PHP 5.

choster’s picture

Path #7 resolves the issue of event nodes not appearing in the calendar, and of the PHP parameter errors in the logs. We are on PHP 5.2.5. Unfortunately, everything displays 8 time zones or so off.

karens’s picture

Status: Reviewed & tested by the community » Fixed

Fixed slightly differently (using date_make_date instead of date_create). Thanks for catching this!

wouter99999’s picture

Title: date_create() expects parameter 2 to be DateTimeZone, string given » warning: date_format() expects parameter 1 to be DateTime, null given

Hi,
When implementing a calendar, I got a lot of these watchdogs warnings (50000+) when clicking on a link in the mini calender. After a while I found out that it was caused by having two calendar views enabled by mistake.
Anyone having this problem: make sure you have only one calendar view enabled in your views.

Wouter

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Goose4all’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Closed (won't fix)

i get the same error but without having 2 calendar views?

i'v just installed both 2.x-dev versions (calendar and date) and if i enable the calendar view and wanna visit the /calendar site, the watchdog gets filed with millions(!! -i am not kidding.. i need to kill the sql-process) of these messages

<em>date_format() expects parameter 1 to be DateTime, null given</em> in <em>/var/www/www.trekking-blog.de/modules/calendar/calendar.inc</em> in Zeile <em>160</em>.

about row 160 of calendar.inc is:

function calendar_build_calendar($view, $items, $params) {
// Remove nodes outside the selected date range.
$values = array();
foreach ($items as $delta => $item) {
if (($item->calendar_start_date >= $view->min_date && $item->calendar_start_date <= $view->max_date)
|| ($item->calendar_end_date >= $view->min_date && $item->calendar_end_date <= $view->max_date)) {
$values[date_format($item->calendar_start_date, 'Y-m-d')][date_format($item->calendar_start_date, 'Y-m-d')][] = $item; <-- this is row 160 -->
}
}

i get this error for ~ 10 rows..

how can we get this fixed? it doesnt work at all...

Goose4all’s picture

Status: Closed (won't fix) » Active

ups.. wrong status set..

karens’s picture

Status: Active » Fixed

Don't reopen an old closed issue with different information. Your message does not have the same cause nor is it the same issue. I need lots more information to know why you're getting that message. Open a new issue and start over by telling me what kind of date you're using, provide an export of your view, and describe where you get the error.

karens’s picture

Status: Fixed » Closed (fixed)
dugh’s picture

I see the same issue as originally reported when adding the calendar block, using the latest dev version of date & calendar. I already have overridden the calendar view to add a date field (to prevent a bigger bug).

date_format() expects parameter 1 to be DateTime

on lines: 821 & 126

richard.e.morton’s picture

Version: 5.x-2.x-dev » 6.x-2.1
Status: Closed (fixed) » Active

* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/nafof.org.uk/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.

given with Calendar and Date 2.1 on D6

R

jferjan’s picture

subscribing

phils-okc’s picture

warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /Applications/MAMP/htdocs/drupal/sites/all/modules/date/date_api_ical.inc on line 568.
warning: date_format() expects parameter 1 to be DateTime, null given in /Applications/MAMP/htdocs/drupal/sites/all/modules/date/date_api_ical.inc on line 654.
warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /Applications/MAMP/htdocs/drupal/sites/all/modules/date/date_api_ical.inc on line 568.
warning: date_format() expects parameter 1 to be DateTime, null given in /Applications/MAMP/htdocs/drupal/sites/all/modules/date/date_api_ical.inc on line 654.

Every thing seams to be saving correctly. My new nodes show up in the all the calendar views including "upcoming".

I'm not sure how to test the ical module. But I get this error whether or not the module is enabled. I have run through the troubleshooting checklist with the iCal module enabled and disabled.

Running php 5.2.6
March 26 dev version of Calendar
March 27 dev version of Date
Cleared all caches and double-checked all date fields and re-saved.

Thanks

arlinsandbulte’s picture

Status: Active » Closed (fixed)

Please, as Karen said, don't open old issues with NEW information. These are not the same issues originally reported.

#20 might be a duplicate of this #417626: Date browser and Calendar works but show errors
#22 is a duplicate of #409476: date_timezone_set() & date_format() error when editing CCK date repeating fields.

richard.e.morton’s picture

Hi Thanks for your reply.

Firstly saying that "as Karen said", I am sorry I dont read every thread on here. it just isn't reasonable to expect that we all do do that. Also different modules have different rules with regard to re-opening threads, I have been told off for not re-opening threads.... you just can't win.

Richard

MikeBC’s picture

/subscribe

avpaderno’s picture

It is useless to subscribe to a report that has been closed. :-)

Nagi21’s picture

Status: Closed (fixed) » Active

warning: date_timezone_set() expects parameter 1 to be DateTime, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal\sites\all\modules\calendar\includes\calendar.inc on line 417.
warning: date_format() expects parameter 1 to be DateTime, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal\sites\all\modules\calendar\includes\calendar.inc on line 419.
warning: date_timezone_set() expects parameter 1 to be DateTime, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal\sites\all\modules\calendar\includes\calendar.inc on line 417.
warning: date_format() expects parameter 1 to be DateTime, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal\sites\all\modules\calendar\includes\calendar.inc on line 419.

i am getting this error....

karens’s picture

Status: Active » Closed (fixed)

#24 Don't reopen reports if you haven't read all the way through them. If you can't be bothered to even read through the issue to see if it's the right one and whether there is already a solution suggested, you're wasting everyone's time.

#27 As said in #17 and #23, don't reopen an old closed report for this. The code has changed drastically in the year since this report was filed so there's no possible way it can be the same thing. And you need to provide a lot more information than an error message, like what you are doing when you see the message, what version you are using, what environment you have, what kind of date field you're using, how your view is set up, etc.

epop’s picture

any solution for this ical error? #22

tlangston’s picture

Am getting the same error here. Have gone thru all troubleshooting steps and nothing corrects the problem. I reported also under Date API thread thinking this is related.

* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/theatricalsinger.com/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.
* warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/theatricalsinger.com/httpdocs/sites/all/modules/calendar/includes/calendar.inc on line 416.

This error is preventing me from accessing date/time config settings and other areas of admin - I ran some tests by turning off this module and was able to get admin functions back so I think it is related. I'm getting a blank page and the log is spitting out the following:

[Wed Jun 10 07:37:49 2009] [error] [client 65.19.75.254] PHP Fatal error: Cannot call overloaded function for non-object in /var/www/vhosts/theatricalsinger.com/httpdocs/includes/module.inc on line 128, referer: http://theatricalsinger.com/user/1

duckydan’s picture

I am having this same error, but only when I am not logged in. If logged in, it's fine. Please excuse my stupidity, but it seems like an anonymous user needs a "default" time zone and is not getting the one from the date API.

duckydan’s picture

Priority: Critical » Normal
Status: Closed (fixed) » Needs work
arlinsandbulte’s picture

Status: Needs work » Closed (fixed)

This issue (issueS, really) has been closed and opened and closed and opened too many times to be of any use any more.
DO NOT REOPEN THIS ISSUE

If you think you are having a similar issue, open a new issue and describe your issue in detail there.

Thanks.