From b536ecd610cedd724d562429a7f8748d0f876f2f Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 16 Jun 2009 02:59:36 +0000 Subject: [PATCH] BUGFIX: Fixed MSSQL date tweak to not accidentally generate default values for dates. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@79311 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 014a011a2..1392890ee 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -261,20 +261,22 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity if(DB::getConn() instanceof MSSQLDatabase) { $this->class = get_class($this); foreach($record as $k => $v) { - // MSSQLDatabase::date() uses datetime for the data type for "Date" and "SSDatetime" - switch($this->db($k)) { - case "Date": - $meridiem = substr($v, strlen($v) - 2, strlen($v)); - $v = substr($v, 0, strlen($v) - 6); - $record[$k] = date('Y-m-d', strtotime($v . ' ' . $meridiem)); - break; + if($v) { + // MSSQLDatabase::date() uses datetime for the data type for "Date" and "SSDatetime" + switch($this->db($k)) { + case "Date": + $meridiem = substr($v, strlen($v) - 2, strlen($v)); + $v = substr($v, 0, strlen($v) - 6); + $record[$k] = date('Y-m-d', strtotime($v . ' ' . $meridiem)); + break; - case "Datetime": - case "SSDatetime": - $meridiem = substr($v, strlen($v) - 2, strlen($v)); - $v = substr($v, 0, strlen($v) - 6); - $record[$k] = date('Y-m-d H:i:s', strtotime($v . ' ' . $meridiem)); - break; + case "Datetime": + case "SSDatetime": + $meridiem = substr($v, strlen($v) - 2, strlen($v)); + $v = substr($v, 0, strlen($v) - 6); + $record[$k] = date('Y-m-d H:i:s', strtotime($v . ' ' . $meridiem)); + break; + } } } }