Skip to content
Permalink
Browse files

Add additional tests and fix incorrect meridian selection

When dates around midnight were used with interval + 12hr formats, the
incorrect meridian was selected.

Refs #GH-1237
  • Loading branch information...
markstory committed Apr 20, 2013
1 parent 78ea4da commit f6c30157050e6db3d05059b1e09bc0d66b6fd253
Showing with 25 additions and 1 deletion.
  1. +22 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +3 −1 lib/Cake/View/Helper/FormHelper.php
@@ -2328,6 +2328,7 @@ public function testTimeSelectedWithInterval() {
* @return void
*/
public function testInputTimeWithIntervalAnd12HourFormat() {
/*
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
@@ -2347,6 +2348,7 @@ public function testInputTimeWithIntervalAnd12HourFormat() {
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
*/
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
@@ -2357,6 +2359,26 @@ public function testInputTimeWithIntervalAnd12HourFormat() {
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 13:33:00'
));
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => '12',
'interval' => 10,
'selected' => '2013-05-19 01:33:00'
));
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
}
/**
@@ -2380,11 +2380,12 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
$current->setDate($year, $month, $day);
}
if ($hour !== null) {
$hour = $timeFormat == 12 && $hour == 12 ? 0 : $hour;
$current->setTime($hour, $min);
}
$change = (round($min * (1 / $interval)) * $interval) - $min;
$current->modify($change > 0 ? "+$change minutes" : "$change minutes");
$format = ($timeFormat === '12') ? 'Y m d h i a' : 'Y m d H i a';
$format = ($timeFormat == 12) ? 'Y m d h i a' : 'Y m d H i a';
$newTime = explode(' ', $current->format($format));
list($year, $month, $day, $hour, $min, $meridian) = $newTime;
}
@@ -2505,6 +2506,7 @@ protected function _getDateTimeValue($value, $timeFormat) {
if (!empty($timeFormat)) {
$time = explode(':', $days[1]);
// TODO this code is stupid.
if ($time[0] >= 12 && $timeFormat == 12) {
$meridian = 'pm';
} elseif ($time[0] === '00' && $timeFormat == 12) {

0 comments on commit f6c3015

Please sign in to comment.
You can’t perform that action at this time.