Skip to content
Permalink
Browse files

Fix errors in 24 hour time generation.

24 hour clocks go from 0-23 no 1-24.
  • Loading branch information...
markstory committed Feb 23, 2014
1 parent 27eb5e0 commit 5114160f672d4138187851312bf5a90fb55f0870
Showing with 32 additions and 9 deletions.
  1. +4 −3 src/View/Widget/DateTime.php
  2. +28 −6 tests/TestCase/View/Widget/DateTimeTest.php
@@ -350,8 +350,9 @@ protected function _hourSelect($options = []) {
];
$is24 = $options['format'] == 24;
$defaultEnd = $is24 ? 24 : 12;
$options['start'] = max(1, $options['start']);
$defaultStart = $is24 ? 0 : 1;
$defaultEnd = $is24 ? 23 : 12;
$options['start'] = max($defaultStart, $options['start']);
$options['end'] = min($defaultEnd, $options['end']);
if ($options['end'] === null) {
@@ -361,7 +362,7 @@ protected function _hourSelect($options = []) {
if (!$is24 && $options['val'] > 12) {
$options['val'] = sprintf('%02d', $options['val'] - 12);
}
if (!$is24 && $options['val'] == 0) {
if (!$is24 && in_array($options['val'], ['00', '0', 0], true)) {
$options['val'] = 12;
}
@@ -541,6 +541,7 @@ public function testRenderHourWidget24() {
'val' => $now,
]);
$this->assertContains('<select name="date[hour]" data-foo="test">', $result);
$this->assertContains('<option value="00">0</option>', $result);
$this->assertContains(
'<option value="01">1</option>',
$result,
@@ -556,18 +557,39 @@ public function testRenderHourWidget24() {
$result,
'selected value present'
);
$this->assertContains(
'<option value="24">24</option>',
$result,
'contains 24 hours'
);
$this->assertContains('<option value="23">23</option>', $result);
$this->assertNotContains('date[day]', $result, 'No day select.');
$this->assertNotContains('value="0"', $result, 'No zero hour');
$this->assertNotContains('value="25"', $result, 'No 25th hour');
$this->assertNotContains('value="24"', $result, 'No 25th hour');
$this->assertNotContains('<select name="date[meridian]">', $result);
$this->assertNotContains('<option value="pm" selected="selected">pm</option>', $result);
}
/**
* test selecting various options in 24 hr mode.
*
* @return void
*/
public function testRenderHour24SelectedValues() {
$now = new \DateTime('2010-09-09 23:00:00');
$data = [
'name' => 'date',
'year' => false,
'month' => false,
'day' => false,
'hour' => [],
'minute' => false,
'second' => false,
'val' => $now,
];
$result = $this->DateTime->render($data);
$this->assertContains('<option value="23" selected="selected">23</option>', $result);
$data['val'] = '2010-09-09 23:00:00';
$result = $this->DateTime->render($data);
$this->assertContains('<option value="23" selected="selected">23</option>', $result);
}
/**
* Test rendering the hour widget in 12 hour mode.
*

0 comments on commit 5114160

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