diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 551a9ea6c..896c172e6 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -902,9 +902,6 @@ class Model extends Object { $dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec'); $timeFields = array('H' => 'hour', 'i' => 'min', 's' => 'sec'); - - $db = $this->getDataSource(); - $format = $db->columns[$type]['format']; $date = array(); if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] != 12 && 'pm' == $data['meridian']) { @@ -947,9 +944,13 @@ class Model extends Object { } } } - $date = str_replace(array_keys($date), array_values($date), $format); + + $format = $this->getDataSource()->columns[$type]['format']; + $day = empty($date['Y']) ? null : $date['Y'] . '-' . $date['m'] . '-' . $date['d'] . ' '; + $hour = empty($date['H']) ? null : $date['H'] . ':' . $date['i'] . ':' . $date['s']; + $date = new DateTime($day . $hour); if ($useNewDate && !empty($date)) { - return $date; + return $date->format($format); } } return $data; diff --git a/cake/tests/cases/libs/model/model_integration.test.php b/cake/tests/cases/libs/model/model_integration.test.php index 1e6c73e21..a8b5a6796 100644 --- a/cake/tests/cases/libs/model/model_integration.test.php +++ b/cake/tests/cases/libs/model/model_integration.test.php @@ -1947,8 +1947,8 @@ class ModelIntegrationTest extends BaseModelTest { 'Featured' => array( 'article_featured_id' => 1, 'category_id' => 1, - 'published_date' => '2008-6-11 00:00:00', - 'end_date' => '2008-6-20 00:00:00' + 'published_date' => '2008-06-11 00:00:00', + 'end_date' => '2008-06-20 00:00:00' )); $this->assertEqual($FeaturedModel->create($data), $expected); @@ -1970,8 +1970,8 @@ class ModelIntegrationTest extends BaseModelTest { $expected = array( 'Featured' => array( - 'published_date' => '2008-6-11 00:00:00', - 'end_date' => '2008-6-20 00:00:00', + 'published_date' => '2008-06-11 00:00:00', + 'end_date' => '2008-06-20 00:00:00', 'article_featured_id' => 1, 'category_id' => 1 ));