Skip to content

Commit

Permalink
Fix incorrectly handled time values around 12:00:00
Browse files Browse the repository at this point in the history
When using 12 hour formats & intervals, values around 12:00 were
incorrecly converted to midnight.

Fixes #2507
  • Loading branch information
markstory committed Dec 19, 2013
1 parent ca2fb6f commit 5bddc47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
37 changes: 37 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -2347,6 +2347,43 @@ public function testTimeSelectedWithInterval() {
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
}

/**
* Test time with selected values around 12:xx:xx
*
* @return void
*/
public function testTimeSelectedWithIntervalTwelve() {
$result = $this->Form->input('Model.start_time', array(
'type' => 'time',
'timeFormat' => 12,
'interval' => 15,
'selected' => '00:00:00'
));
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
$this->assertContains('<option value="00" selected="selected">00</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' => 15,
'selected' => '12:00:00'
));
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
$this->assertContains('<option value="00" selected="selected">00</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' => 15,
'selected' => '12:15:00'
));
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
$this->assertContains('<option value="15" selected="selected">15</option>', $result);
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
}

/**
* Test interval & timeFormat = 12
*
Expand Down
4 changes: 0 additions & 4 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -2391,10 +2391,6 @@ public function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $a
$round = $attributes['round'];
$attributes = array_diff_key($attributes, $defaults);

if ($timeFormat == 12 && $hour == 12) {
$hour = 0;
}

if (!empty($interval) && $interval > 1 && !empty($min)) {
$current = new DateTime();
if ($year !== null) {
Expand Down

0 comments on commit 5bddc47

Please sign in to comment.