From 30f332cd21f0dca6102124442dfe11715207ddd7 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Mon, 21 Dec 2009 21:49:12 +0000 Subject: [PATCH] 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 --- core/model/fieldtypes/Date.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/model/fieldtypes/Date.php b/core/model/fieldtypes/Date.php index 26047b938..9b3d8afab 100644 --- a/core/model/fieldtypes/Date.php +++ b/core/model/fieldtypes/Date.php @@ -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 */