? 831470-22_date_conversion.patch
? 831470-23_date_conversion.patch
? libraries/simplepie.inc
Index: plugins/FeedsParser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsParser.inc,v
retrieving revision 1.22.2.1
diff -u -p -r1.22.2.1 FeedsParser.inc
--- plugins/FeedsParser.inc	25 Sep 2010 15:31:08 -0000	1.22.2.1
+++ plugins/FeedsParser.inc	25 Sep 2010 16:45:06 -0000
@@ -487,19 +487,33 @@ class FeedsDateTime extends DateTime {
    *   PHP DateTimeZone object, NULL allowed
    */
   public function __construct($time = '', $tz = NULL) {
+    // Assume UNIX timestamp if numeric.
     if (is_numeric($time)) {
-      // Assume timestamp.
       $time = "@". $time;
     }
+
     // PHP < 5.3 doesn't like the GMT- notation for parsing timezones.
     $time = str_replace("GMT-", "-", $time);
     $time = str_replace("GMT+", "+", $time);
-    parent::__construct($time, $tz ? $tz : new DateTimeZone("UTC"));
-    $this->setGranularityFromTime($time, $tz);
+
+    // Some PHP 5.2 version's DateTime class chokes on invalid dates.
+    if (!strtotime($time)) {
+      $time = 'now';
+    }
+
+    // Create and set time zone separately, PHP 5.2.6 does not respect time zone
+    // argument in __construct().
+    parent::__construct($time);
+    $tz = $tz ? $tz : new DateTimeZone("UTC");
+    $this->setTimeZone($tz);
+
+    // Verify that timezone has not been specified as an offset.
     if (!preg_match('/[a-zA-Z]/', $this->getTimezone()->getName())) {
-      // This tz was given as just an offset, which causes problems
       $this->setTimezone(new DateTimeZone("UTC"));
     }
+
+    // Finally set granularity.
+    $this->setGranularityFromTime($time, $tz);
   }
 
   /**
Index: tests/feeds_date_time.test
===================================================================
RCS file: tests/feeds_date_time.test
diff -N tests/feeds_date_time.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/feeds_date_time.test	25 Sep 2010 16:45:06 -0000
@@ -0,0 +1,49 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Tests for FeedsDateTime class.
+ */
+
+/**
+ * Test FeedsDateTime class.
+ *
+ * Using DrupalWebTestCase as DrupalUnitTestCase is broken in SimpleTest 2.8.
+ * Not inheriting from Feeds base class as ParserCSV should be moved out of
+ * Feeds at some time.
+ */
+class FeedsDateTimeTest extends DrupalWebTestCase  {
+  /**
+   * Describe this test.
+   */
+  public function getInfo() {
+    return array(
+      'name' => t('FeedsDateTime unit tests'),
+      'description' => t('Unit tests for Feeds date handling.'),
+      'group' => t('Feeds'),
+    );
+  }
+
+  /**
+   * Set up.
+   */
+  public function setUp() {
+    parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler');
+    // Trick feeds into loading the FeedsParser class file.
+    // @todo: break out FeedsElement and children into its own include file.
+    feeds_plugin_instance('FeedsCSVParser', 'test');
+  }
+
+  /**
+   * Dispatch tests, only use one entry point method testX to save time.
+   */
+  public function test() {
+    $date = new FeedsDateTime('2010-20-12');
+    $this->assertTrue(is_numeric($date->format('U')));
+    $date = new FeedsDateTime('created');
+    $this->assertTrue(is_numeric($date->format('U')));
+    $date = new FeedsDateTime('12/3/2009 20:00:10');
+    $this->assertTrue(is_numeric($date->format('U')));
+  }
+}
