mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making dates deconstruction in model more consistent for different datasources
This commit is contained in:
parent
41ee035d28
commit
0ff01330c4
2 changed files with 10 additions and 9 deletions
|
@ -902,9 +902,6 @@ class Model extends Object {
|
||||||
|
|
||||||
$dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec');
|
$dateFields = array('Y' => 'year', 'm' => 'month', 'd' => 'day', 'H' => 'hour', 'i' => 'min', 's' => 'sec');
|
||||||
$timeFields = array('H' => 'hour', 'i' => 'min', 's' => 'sec');
|
$timeFields = array('H' => 'hour', 'i' => 'min', 's' => 'sec');
|
||||||
|
|
||||||
$db = $this->getDataSource();
|
|
||||||
$format = $db->columns[$type]['format'];
|
|
||||||
$date = array();
|
$date = array();
|
||||||
|
|
||||||
if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] != 12 && 'pm' == $data['meridian']) {
|
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)) {
|
if ($useNewDate && !empty($date)) {
|
||||||
return $date;
|
return $date->format($format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -1947,8 +1947,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
||||||
'Featured' => array(
|
'Featured' => array(
|
||||||
'article_featured_id' => 1,
|
'article_featured_id' => 1,
|
||||||
'category_id' => 1,
|
'category_id' => 1,
|
||||||
'published_date' => '2008-6-11 00:00:00',
|
'published_date' => '2008-06-11 00:00:00',
|
||||||
'end_date' => '2008-6-20 00:00:00'
|
'end_date' => '2008-06-20 00:00:00'
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEqual($FeaturedModel->create($data), $expected);
|
$this->assertEqual($FeaturedModel->create($data), $expected);
|
||||||
|
@ -1970,8 +1970,8 @@ class ModelIntegrationTest extends BaseModelTest {
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'Featured' => array(
|
'Featured' => array(
|
||||||
'published_date' => '2008-6-11 00:00:00',
|
'published_date' => '2008-06-11 00:00:00',
|
||||||
'end_date' => '2008-6-20 00:00:00',
|
'end_date' => '2008-06-20 00:00:00',
|
||||||
'article_featured_id' => 1,
|
'article_featured_id' => 1,
|
||||||
'category_id' => 1
|
'category_id' => 1
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in a new issue