Skip to content

Commit 0ff0133

Browse files
committed
Making dates deconstruction in model more consistent for different datasources
1 parent 41ee035 commit 0ff0133

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

cake/libs/model/model.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,6 @@ public function deconstruct($field, $data) {
902902

903903
$dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec');
904904
$timeFields = array('H' => 'hour', 'i' => 'min', 's' => 'sec');
905-
906-
$db = $this->getDataSource();
907-
$format = $db->columns[$type]['format'];
908905
$date = array();
909906

910907
if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] != 12 && 'pm' == $data['meridian']) {
@@ -947,9 +944,13 @@ public function deconstruct($field, $data) {
947944
}
948945
}
949946
}
950-
$date = str_replace(array_keys($date), array_values($date), $format);
947+
948+
$format = $this->getDataSource()->columns[$type]['format'];
949+
$day = empty($date['Y']) ? null : $date['Y'] . '-' . $date['m'] . '-' . $date['d'] . ' ';
950+
$hour = empty($date['H']) ? null : $date['H'] . ':' . $date['i'] . ':' . $date['s'];
951+
$date = new DateTime($day . $hour);
951952
if ($useNewDate && !empty($date)) {
952-
return $date;
953+
return $date->format($format);
953954
}
954955
}
955956
return $data;

cake/tests/cases/libs/model/model_integration.test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,8 +1947,8 @@ function testCreation() {
19471947
'Featured' => array(
19481948
'article_featured_id' => 1,
19491949
'category_id' => 1,
1950-
'published_date' => '2008-6-11 00:00:00',
1951-
'end_date' => '2008-6-20 00:00:00'
1950+
'published_date' => '2008-06-11 00:00:00',
1951+
'end_date' => '2008-06-20 00:00:00'
19521952
));
19531953

19541954
$this->assertEqual($FeaturedModel->create($data), $expected);
@@ -1970,8 +1970,8 @@ function testCreation() {
19701970

19711971
$expected = array(
19721972
'Featured' => array(
1973-
'published_date' => '2008-6-11 00:00:00',
1974-
'end_date' => '2008-6-20 00:00:00',
1973+
'published_date' => '2008-06-11 00:00:00',
1974+
'end_date' => '2008-06-20 00:00:00',
19751975
'article_featured_id' => 1,
19761976
'category_id' => 1
19771977
));

0 commit comments

Comments
 (0)