mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fixed Rfc3339 implementation of Date and Datetime
This commit is contained in:
parent
1a421dc947
commit
6fafce766e
@ -322,19 +322,7 @@ class DBDate extends DBField
|
|||||||
*/
|
*/
|
||||||
public function Rfc3339()
|
public function Rfc3339()
|
||||||
{
|
{
|
||||||
$date = $this->Format('y-MM-dd\\THH:mm:ss');
|
return date('c', $this->getTimestamp());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -330,4 +330,11 @@ class DBDateTest extends SapphireTest
|
|||||||
|
|
||||||
DBDatetime::clear_mock_now();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,4 +204,11 @@ class DBDatetimeTest extends SapphireTest
|
|||||||
|
|
||||||
DBDatetime::clear_mock_now();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user