Error when mapping timestamps to cck date fields

halstead - July 10, 2009 - 00:07
Project:Feed Element Mapper
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:minor
Assigned:halstead
Status:fixed
Description

Checked out of CVS today (June 9th 2009). Running on Windows, Apache 2.2.x, MySQL database 5.1.34, and PHP 5.2.9-2.

warning: date_timezone_set() expects parameter 2 to be DateTimeZone, string given in C:\Drupal\drupal\sites\all\modules\feedapi_mapper\mappers\feedapi_mapper_date.inc on line 141.

I fixed it by replacing line #141 in mappers/feedapi_mapper_date.inc:
  date_timezone_set($value, $to_tz);
With:

  $tz_object = new DateTimeZone($to_tz);
  date_timezone_set($value, $tz_object);

#1

alex_b - July 31, 2009 - 11:57
Status:needs work» duplicate

This seems to be fixed now - duplicate of ? #504852-4: Warning in feedapi_mapper_date.inc

#2

halstead - August 13, 2009 - 17:32
Status:duplicate» needs review

I think this is a different issue because it is still present, it's on a different line, and the error message is a bit different. Here is the error with the newest 6.x-1.x:

warning: date_timezone_set() expects parameter 2 to be DateTimeZone, string given in C:\Users\MichaelH\workspace\Sites\acquia-drupal\drupal\sites\all\modules\feedapi_mapper\mappers\feedapi_mapper_date.inc on line 142.

The patch that removed the error for me is attached.

AttachmentSize
feedapi_mapper-515190.patch 915 bytes

#3

alex_b - August 14, 2009 - 13:32

#2 - thank you. Good catch. Can you explain what your patch fixes?

#4

halstead - August 15, 2009 - 00:51

Right now a string such as 'Europe/London' is being passed to the function which is expecting a DateTimeZone object so a warning is triggered. I'm creating a DateTimeZone object from the string and passing that instead. This removes the warning.

http://us.php.net/manual/en/datetime.settimezone.php
http://us.php.net/manual/en/datetimezone.construct.php

Perhaps the patch should be changed to catch the exception thrown when an unknown timezone string is passed. Something like:

  try {
    $tz_object = new DateTimeZone($to_tz);
  } catch (Exception $e) {
    drupal_set_message($e->getMessage());
  }

How do you feel about that?

#5

alex_b - August 17, 2009 - 11:51

"Perhaps the patch should be changed to catch the exception thrown when an unknown timezone string is passed."

I think that's an excellent idea.

#6

halstead - August 17, 2009 - 19:06

Okay I made it revert to the original behavior if the DateTimeZone object can't be created. I also added a PHP >= 5.2.0 requirement to the info file since date_timezone_set() was introduced in PHP 5.2 and exception handling was added in PHP 5.

AttachmentSize
feedapi_mapper-515190.patch 1.64 KB

#7

Aron Novak - August 18, 2009 - 15:10
Status:needs review» reviewed & tested by the community

I tested it and it does not make any harm.
It should be committed for both 1.x and 2.x

#8

alex_b - August 24, 2009 - 00:29

Nice work. RTBC from me, too.

#9

halstead - September 15, 2009 - 17:40
Assigned to:Anonymous» halstead

#10

halstead - November 19, 2009 - 22:30
Status:reviewed & tested by the community» fixed

The problem has been resolved in a different manner (using timezone_open) in 6.x-1.3.

 
 

Drupal is a registered trademark of Dries Buytaert.