Skip to content

Commit

Permalink
Fix issue with incorrect date handling.
Browse files Browse the repository at this point in the history
Fixes #2321
  • Loading branch information
markstory committed Dec 3, 2011
1 parent 22352a0 commit 0670b96
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/Cake/Model/Model.php
Expand Up @@ -1184,12 +1184,14 @@ public function deconstruct($field, $data) {
}
}

$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->format($format);
$format = $this->getDataSource()->columns[$type]['format'];
foreach (array('m', 'd', 'H', 'i', 's') as $index) {
if (isset($date[$index])) {
$date[$index] = sprintf('%02d', $date[$index]);
}
}
return str_replace(array_keys($date), array_values($date), $format);
}
}
return $data;
Expand Down

0 comments on commit 0670b96

Please sign in to comment.