Permalink
Browse files

Fix missed case for midnight in 12 hour format.

  • Loading branch information...
1 parent a53e690 commit 27eb5e0291da6cd915a661746ffbd3f392e33a52 @markstory markstory committed Feb 23, 2014
Showing with 29 additions and 1 deletion.
  1. +3 −1 src/View/Widget/DateTime.php
  2. +26 −0 tests/TestCase/View/Widget/DateTimeTest.php
@@ -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']);
@@ -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(
@@ -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.
*

0 comments on commit 27eb5e0

Please sign in to comment.