diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc index 13fcaa0de93db7294914dceeba1845f04617e728..002f69eac02ab01096a9fe17c3f13727a9a90b38 100644 --- a/plugins/FeedsParser.inc +++ b/plugins/FeedsParser.inc @@ -592,12 +592,17 @@ class FeedsDateTime extends DateTime { * PHP DateTimeZone object, NULL allowed */ public function __construct($time = '', $tz = NULL) { - // Assume UNIX timestamp if numeric. if (is_numeric($time)) { - // Make sure it's not a simple year - if ((is_string($time) && strlen($time) > 4) || is_int($time)) { + // Assume UNIX timestamp if it doesn't look like a simple year. + if (strlen($time) > 4) { $time = "@" . $time; } + // If it's a year, add a default month too, because PHP's date functions + // won't parse standalone years after 2000 correctly (see explanation at + // http://aaronsaray.com/blog/2007/07/11/helpful-strtotime-reminders/#comment-47). + else { + $time = 'January ' . $time; + } } // PHP < 5.3 doesn't like the GMT- notation for parsing timezones. diff --git a/tests/feeds_date_time.test b/tests/feeds_date_time.test index a4494581dd91e4e16e8c8e32ae6497784ff04cde..8ced8438cc2fc21290310e55af4663a2f83b751d 100644 --- a/tests/feeds_date_time.test +++ b/tests/feeds_date_time.test @@ -38,5 +38,11 @@ class FeedsDateTimeTest extends FeedsWebTestCase { $this->assertTrue(is_numeric($date->format('U'))); $date = new FeedsDateTime('12/3/2009 20:00:10'); $this->assertTrue(is_numeric($date->format('U'))); + + // Check that years above 2000 work correctly. + $date1 = new FeedsDateTime(2012); + $date2 = new FeedsDateTime('January 2012'); + $this->assertEqual($date1->format('U'), $date2->format('U')); } + }