Skip to content

Commit

Permalink
Fix missed case for midnight in 12 hour format.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 25, 2014
1 parent a53e690 commit 27eb5e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/View/Widget/DateTime.php
Expand Up @@ -351,7 +351,6 @@ protected function _hourSelect($options = []) {
$is24 = $options['format'] == 24;

$defaultEnd = $is24 ? 24 : 12;

$options['start'] = max(1, $options['start']);

$options['end'] = min($defaultEnd, $options['end']);
Expand All @@ -362,6 +361,9 @@ protected function _hourSelect($options = []) {
if (!$is24 && $options['val'] > 12) {
$options['val'] = sprintf('%02d', $options['val'] - 12);
}
if (!$is24 && $options['val'] == 0) {
$options['val'] = 12;
}

if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers(
Expand Down
26 changes: 26 additions & 0 deletions tests/TestCase/View/Widget/DateTimeTest.php
Expand Up @@ -616,6 +616,32 @@ public function testRenderHourWidget12() {
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
}

/**
* Test rendering hour widget in 12 hour mode at midnight.
*
* @return void
*/
public function testRenderHourWidget12Midnight() {
$now = new \DateTime('2010-09-09 00:30:45');
$result = $this->DateTime->render([
'name' => 'date',
'year' => false,
'month' => false,
'day' => false,
'hour' => [
'format' => 12,
],
'minute' => false,
'second' => false,
'val' => $now,
]);
$this->assertContains(
'<option value="12" selected="selected">12</option>',
$result,
'12 is selected'
);
}

/**
* Test rendering the hour picker in 12 hour mode.
*
Expand Down

0 comments on commit 27eb5e0

Please sign in to comment.