Skip to content
Snippets Groups Projects
Commit 2c05963b authored by drothstein's avatar drothstein Committed by Chris Leppanen
Browse files

Issue #1537776 by David_Rothstein | RyFo18: Importing a single 21st century...

Issue #1537776 by David_Rothstein | RyFo18: Importing a single 21st century year defaults to the current year.
parent ec5d6f7e
No related branches found
No related tags found
No related merge requests found
...@@ -592,12 +592,17 @@ class FeedsDateTime extends DateTime { ...@@ -592,12 +592,17 @@ class FeedsDateTime extends DateTime {
* PHP DateTimeZone object, NULL allowed * PHP DateTimeZone object, NULL allowed
*/ */
public function __construct($time = '', $tz = NULL) { public function __construct($time = '', $tz = NULL) {
// Assume UNIX timestamp if numeric.
if (is_numeric($time)) { if (is_numeric($time)) {
// Make sure it's not a simple year // Assume UNIX timestamp if it doesn't look like a simple year.
if ((is_string($time) && strlen($time) > 4) || is_int($time)) { if (strlen($time) > 4) {
$time = "@" . $time; $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. // PHP < 5.3 doesn't like the GMT- notation for parsing timezones.
......
...@@ -38,5 +38,11 @@ class FeedsDateTimeTest extends FeedsWebTestCase { ...@@ -38,5 +38,11 @@ class FeedsDateTimeTest extends FeedsWebTestCase {
$this->assertTrue(is_numeric($date->format('U'))); $this->assertTrue(is_numeric($date->format('U')));
$date = new FeedsDateTime('12/3/2009 20:00:10'); $date = new FeedsDateTime('12/3/2009 20:00:10');
$this->assertTrue(is_numeric($date->format('U'))); $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'));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment