Skip to content

Commit

Permalink
Making dates deconstruction in model more consistent for different da…
Browse files Browse the repository at this point in the history
…tasources
  • Loading branch information
lorenzo committed Nov 27, 2010
1 parent 41ee035 commit 0ff0133
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions cake/libs/model/model.php
Expand Up @@ -902,9 +902,6 @@ public function deconstruct($field, $data) {

$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']) {
Expand Down Expand Up @@ -947,9 +944,13 @@ public function deconstruct($field, $data) {
}
}
}
$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;
Expand Down
8 changes: 4 additions & 4 deletions cake/tests/cases/libs/model/model_integration.test.php
Expand Up @@ -1947,8 +1947,8 @@ function testCreation() {
'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);
Expand All @@ -1970,8 +1970,8 @@ function testCreation() {

$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
));
Expand Down

0 comments on commit 0ff0133

Please sign in to comment.