Merge pull request #7796 from bummzack/fix-date-rfc3339

Fixed Rfc3339 implementation of Date and Datetime
This commit is contained in:
Damian Mooyman 2018-01-25 11:44:53 +13:00 committed by GitHub
commit f764ab04e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -322,19 +322,7 @@ class DBDate extends DBField
*/
public function Rfc3339()
{
$date = $this->Format('y-MM-dd\\THH:mm:ss');
if (!$date) {
return null;
}
$matches = array();
if (preg_match('/^([\-+])(\d{2})(\d{2})$/', date('O', $this->getTimestamp()), $matches)) {
$date .= $matches[1] . $matches[2] . ':' . $matches[3];
} else {
$date .= 'Z';
}
return $date;
return date('c', $this->getTimestamp());
}
/**

View File

@ -330,4 +330,11 @@ class DBDateTest extends SapphireTest
DBDatetime::clear_mock_now();
}
public function testRfc3999()
{
// Dates should be formatted as: 2018-01-24T14:05:53+00:00
$date = DBDate::create_field('Date', '2010-12-31');
$this->assertEquals('2010-12-31T00:00:00+00:00', $date->Rfc3339());
}
}

View File

@ -204,4 +204,11 @@ class DBDatetimeTest extends SapphireTest
DBDatetime::clear_mock_now();
}
public function testRfc3999()
{
// Dates should be formatted as: 2018-01-24T14:05:53+00:00
$date = DBDatetime::create_field('Datetime', '2010-12-31 16:58:59');
$this->assertEquals('2010-12-31T16:58:59+00:00', $date->Rfc3339());
}
}