Was running into this error with 7.x-2.2 (and 7.x-2.1 when I moved back to it for testing):

Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in DateObject->__construct() (line 273 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in DateObject->__construct() (line 278 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in DateObject->__construct() (line 215 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::setTimezone() [datetime.settimezone]: The DateTime object has not been correctly initialized by its constructor in DateObject->setTimezone() (line 281 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::setDate() [datetime.setdate]: The DateTime object has not been correctly initialized by its constructor in DateObject->setTimezone() (line 282 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: DateTime::setTime() [datetime.settime]: The DateTime object has not been correctly initialized by its constructor in DateObject->setTimezone() (line 283 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).
Warning: date_timezone_set() [function.date-timezone-set]: The DateTime object has not been correctly initialized by its constructor in date_context_date_condition->execute() (line 135 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_context\date_context.module).
Warning: DateTime::format() [datetime.format]: The DateTime object has not been correctly initialized by its constructor in DateObject->format() (line 307 of C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module).

Tried upgrading to 7.x-2.5, then tried 2.3 through dev and got this with all of them:
Fatal error: Call to a member function getName() on a non-object in C:\joshua-www\MWL\sites\all\modules\contrib\date\date_api\date_api.module on line 278

Both of these seem to be issues with initializing the timezone. I've checked the site is setup with the timezone etc.

Stumped here - any ideas? Looks like the first issue has been hit before (#1222464: Latest dev release breaks Calendar.) and in comment 15 someone hit this just a week or two ago (and that person cross-posted #1025920: error when going to calendar view). The second issue has been mentioned in a forum post (http://drupal.org/node/1535294).

Happy to try things out, just not sure what to try at this point - ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

videographics’s picture

I can confirm that with with 7.x-2.5 I'm getting:

 Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in DateObject->__construct() (line 273 of /example.com/sites/all/modules/date/date_api/date_api.module).
zabelc’s picture

I'm seeing a similar error on a view which deals rather heavily with dates, date filters, and date ordering:

Fatal error: Call to a member function getName() on a non-object in /home/patcms/public_html/sites/all/modules/date/date_api/date_api.module on line 278

I'm also seeing this on the date-7.x-2.5

zabelc’s picture

FWIW I added a dpm at line 274, and discovered the following:

this->getTimezone() =>

I was able to get this error to go away by modifying the if statement as follows:

      // If the timezone name is an offset and the original
      // $tz has a name, use it. This happens if you pass in
      // a date string with an offset along with a specific timezone name.
      if ( method_exists($this->getTimezone(), 'getName')
      	&& !preg_match('/[a-zA-Z]/', $this->getTimezone()->getName()) 
      	&& preg_match('/[a-zA-Z]/', $tz->getName())) {
        $this->setTimezone($tz);
      }
ndrosev’s picture

Check way of declaring DateObject . For me the problem comes from $time_start_obj = new DateObject(reset($start_times), 'UTC');
I fixed it when I add format of DateObject
$time_start_obj = new DateObject(reset($start_times), 'UTC', DATE_FORMAT_DATETIME); - correct

KarenS’s picture

Status: Active » Postponed (maintainer needs more info)

I do not get this error. I have to know how to reproduce it on a clean install. You have some other module enabled or something. There are thousands of installations and only 3 people are reporting this, so there's something non-standard going on. See if you can trigger this error on a clean install of only Date module. If you can't, you will have to try adding in other modules you are using and see if one of them seems to trigger it.

Also you need to see if you have errors when using the latest -dev version of the code (rather than specific releases). If there is no problem using -dev, the problem, whatever it is, is already fixed.

sokrplare’s picture

Thanks Karen, I know it is non-standard. Normally I'd hit the steps you mentioned but in this case we're stuck on this version of Date due to other dependencies so just floated this out here to see if others are hitting as well. You can probably ignore and focus on more important stuff and we'll just huddle out a solution together over here :)

varunity’s picture

I was getting this error but solved it by realizing that the date field on the node in question was empty. I added some values and viola, it worked and the error disappeared.

sokrplare’s picture

Title: getName() error on getTimezone() returned object in 7.x-2.3+ and DateTime initialization error in 7.x-2.2 » The DateTime object has not been correctly initialized by its constructor in date_context_date_condition->execute() (line 135)
Version: 7.x-2.2 » 7.x-2.x-dev
Status: Postponed (maintainer needs more info) » Needs review
FileSize
862 bytes

@KarenS - so I'd thought it was likely a misconfiguration on our part (big team working on this site), but digging in more I think it might truly be a bug in date_context.

Patch attached against 7.x-2.x-dev. Pretty straightforward - basically the scenario to get this error is:

  1. Enable the date context module
  2. Add a date field to a content type with only a single date (value2 will be empty)
  3. Setup a context to compare the date field
  4. Add date data to that field and then view/edit the node

Clearly, I'm not too familiar with the inner workings of the date module so I could be way off base here, but I did see similar !empty checks being performed elsewhere and it seemed logical for here.

sokrplare’s picture

Title: The DateTime object has not been correctly initialized by its constructor in date_context_date_condition->execute() (line 135) » Date Context:The DateTime object has not been correctly initialized by its constructor in date_context_date_condition->execute()
Status: Needs review » Reviewed & tested by the community

Got to upgrade to 7.x-2.5 for this project - hooray! Error appeared again (which makes sense patch is against dev) and reapplied with success!

mrfelton’s picture

Status: Reviewed & tested by the community » Needs work

I have this problem when trying to use the date_sql_handler class from within a cron job. I'm not using date_context.

Niremizov’s picture

I have similar errors. I understand that it could easily be not the Date module's issue, but Field Collection (in my case).

Installation

(this modules are needed to reproduce error):
Drupal core - 7.14
date-7.x-2.x-dev -- "2012-Jun-20"
field_collection-7.x-1.x-dev -- "2012-Jun-28"

Steps of reproducing errors:

1. Add 2 "Field Collection" fields to content type with unlimited cardinality.
2. Add to each "Field Collection" one "Date Field": (in my case) granularity: year, collect End date: True (and Required), cardinality equal to 1, widget-select.
3. Add new content. In the first "Field Collection" - "Date Field" make start date greater than end date.
4. Click "Save Content" button.
5. After getting warning "End date should be greater than start date.", click "Add more" button of the second "Field Collection" - "Date Field".

After that you will receive:

Notice: Undefined index: timezone in function date_field_validate() (string 351 в файле C:\...l\sites\all\modules\date\date.field.inc).
Notice: Undefined index: timezone in function date_field_validate() (string 356 в файле C:\...\sites\all\modules\date\date.field.inc).
Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in function DateObject->__construct() (string 273 в файле C:\...\sites\all\modules\date\date_api\date_api.module).
Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in function DateObject->__construct() (string 278 в файле C:\...\sites\all\modules\date\date_api\date_api.module).
Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in function DateObject->__construct() (string 273 в файле C:\...\sites\all\modules\date\date_api\date_api.module).
Warning: DateTime::getTimezone() [datetime.gettimezone]: The DateTime object has not been correctly initialized by its constructor in function DateObject->__construct() (string 278 в файле C:\...\sites\all\modules\date\date_api\date_api.module).

I suppose that steps could differ...

For some reason __construct function receive $time variable as an DateObject.

PS: None of upper solutions helped...

Letharion’s picture

Component: Date Timezone » Code
Status: Needs work » Reviewed & tested by the community

@mrfelton in #10, please open a different issue then.

The OP clearly found a bug in DateContext, and named the issue as such. Please don't confuse the topic by keeping more than one problem in this one issue.

I've reviewed the patch, debugged date_context, and tested the patch.

My initial reaction was that if there's no end date (value2), then perhaps the entire logic should just be simplified instead of the start date being used. However, after looking some more at the code, I think the patch is solid.

It's not necessarily the prettiest solution, but given that the date context currently is quite broken without end-dates, I think it should go in.

KarenS’s picture

Status: Reviewed & tested by the community » Fixed

I agree with the fix for Date Context. If there is a problem with Field Collection that should be handled in a new issue. I have no idea what else might be the cause of mrfelton's problem, so that belongs elsewhere. This issue has a specific cause and fix.

http://drupalcode.org/project/date.git/commit/ced9274

Status: Fixed » Closed (fixed)

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

ashwinsh’s picture

Hi Zabelc,

Thank you for your valuable solution..! It's work for me.! :)
(For #3 Reply)