Browse Source

Fix missed case for midnight in 12 hour format.

Mark Story 12 years ago
parent
commit
27eb5e0291
2 changed files with 29 additions and 1 deletions
  1. 3 1
      src/View/Widget/DateTime.php
  2. 26 0
      tests/TestCase/View/Widget/DateTimeTest.php

+ 3 - 1
src/View/Widget/DateTime.php

@@ -351,7 +351,6 @@ class DateTime implements WidgetInterface {
 		$is24 = $options['format'] == 24;
 
 		$defaultEnd = $is24 ? 24 : 12;
-
 		$options['start'] = max(1, $options['start']);
 
 		$options['end'] = min($defaultEnd, $options['end']);
@@ -362,6 +361,9 @@ class DateTime implements WidgetInterface {
 		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(

+ 26 - 0
tests/TestCase/View/Widget/DateTimeTest.php

@@ -617,6 +617,32 @@ class DateTimeTest extends TestCase {
 	}
 
 /**
+ * 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.
  *
  * @return void