mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added Date::Rfc3339() for returning an RFC 3339 valid date format (from r96010) (from r96049)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102324 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
bf57bee1f0
commit
eba3409c20
@ -124,6 +124,22 @@ class Date extends DBField {
|
|||||||
if($this->value) return date('r', strtotime($this->value));
|
if($this->value) return date('r', strtotime($this->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Rfc3339() {
|
||||||
|
$timestamp = ($this->value) ? strtotime($this->value) : false;
|
||||||
|
if(!$timestamp) return false;
|
||||||
|
|
||||||
|
$date = date('Y-m-d\TH:i:s', $timestamp);
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
if(preg_match('/^([\-+])(\d{2})(\d{2})$/', date('O', $timestamp), $matches)) {
|
||||||
|
$date .= $matches[1].$matches[2].':'.$matches[3];
|
||||||
|
} else {
|
||||||
|
$date .= 'Z';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of seconds/minutes/hours/days or months since the timestamp
|
* Returns the number of seconds/minutes/hours/days or months since the timestamp
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user