ENHANCEMENT Added Date::Rfc3339() for returning an RFC 3339 valid date format (from r96010)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96049 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-12-21 21:49:12 +00:00 committed by Sam Minnee
parent 69229baeaf
commit 30f332cd21

View File

@ -121,6 +121,22 @@ class Date extends DBField {
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
*/