This was originally reported in #2325207: DateTimeZone could not be converted to string and supposedly fixed in 7.x-2.10, however the applied "fix" never actually fixed this fatal error, as demonstrated by the tests #2325207-22: DateTimeZone could not be converted to string.

Since I cannot re-open that issue, this is a "follow-up" issue for the same bug.

Original report by bugster

Recoverable fatal error: Object of class DateTimeZone could not be converted to string in date_now() (line 1753 of modules/date/date_api/date_api.module).

I do have php 5.5.9, I guess they removed the __toString function from this class

Cause reported by jojonaloha in #2325207-2: DateTimeZone could not be converted to string

This bug was introduced in #2261395: date_now is not respecting changes to timezone.

The reason is DateTimeZone doesn't have a __toString() method and the issue assumed it was always a string, even though the code comment suggests it is always an object.

Proposed Fix

Update the code comment to better reflect the accepted parameters (same as the DateObject constructor)
Add tests to prove the bug exists and prevent it from being re-introduced
Fix the bug by handling DateTimeZone objects when building the static variable name.

Comments

jojonaloha created an issue. See original summary.

jojonaloha’s picture

Original patch that only includes tests from #2325207-22: DateTimeZone could not be converted to string

This should fail, proving the bug still exists.

jojonaloha’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: date-datetimezone-converted-to-string-2325207-22--tests-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jojonaloha’s picture

Status: Needs work » Needs review
StatusFileSize
new4.4 KB

And the original patch from https://www.drupal.org/node/2325207#comment-10543380 with tests that should pass.

Status: Needs review » Needs work

The last submitted patch, 5: date-datetimezone-converted-to-string-2325207-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jojonaloha’s picture

Status: Needs work » Needs review

Putting back to Needs Review because the new test passes and the code sniffer changes have nothing to do with the changes made in this patch.

goz’s picture

Status: Needs review » Reviewed & tested by the community

I have the same issue. Patch apply and works as expected.

Thanks jojonaloha.

damienmckenna’s picture

StatusFileSize
new840 bytes
new2.93 KB

A slight tidying of the test's setUp() method.

damienmckenna’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: date-n2880395-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

damienmckenna’s picture

Status: Needs work » Needs review
StatusFileSize
new2.91 KB

Apologies, I didn't realize that DrupalUnitTestCase required the setUp() method use drupal_load() to load modules.

damienmckenna’s picture

Status: Needs review » Postponed

Committed. Thanks!

damienmckenna’s picture

Status: Postponed » Fixed

Status: Fixed » Closed (fixed)

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