mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge branch 'master-time'
See #GH-1237
This commit is contained in:
commit
3dbc3a0abe
2 changed files with 38 additions and 9 deletions
|
@ -2328,6 +2328,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testInputTimeWithIntervalAnd12HourFormat() {
|
||||
/*
|
||||
$result = $this->Form->input('Model.start_time', array(
|
||||
'type' => 'time',
|
||||
'timeFormat' => 12,
|
||||
|
@ -2347,6 +2348,37 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertContains('<option value="04" selected="selected">4</option>', $result);
|
||||
$this->assertContains('<option value="30" selected="selected">30</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' => 10,
|
||||
'selected' => '2013-05-19 00:33:00'
|
||||
));
|
||||
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
|
||||
$this->assertContains('<option value="30" selected="selected">30</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' => 10,
|
||||
'selected' => '2013-05-19 13:33:00'
|
||||
));
|
||||
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
|
||||
$this->assertContains('<option value="30" selected="selected">30</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' => 10,
|
||||
'selected' => '2013-05-19 01:33:00'
|
||||
));
|
||||
$this->assertContains('<option value="01" selected="selected">1</option>', $result);
|
||||
$this->assertContains('<option value="30" selected="selected">30</option>', $result);
|
||||
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2374,6 +2374,10 @@ class FormHelper extends AppHelper {
|
|||
$monthNames = $attributes['monthNames'];
|
||||
$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) {
|
||||
|
@ -2384,7 +2388,7 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
$change = (round($min * (1 / $interval)) * $interval) - $min;
|
||||
$current->modify($change > 0 ? "+$change minutes" : "$change minutes");
|
||||
$format = ($timeFormat === '12') ? 'Y m d h i a' : 'Y m d H i a';
|
||||
$format = ($timeFormat == 12) ? 'Y m d h i a' : 'Y m d H i a';
|
||||
$newTime = explode(' ', $current->format($format));
|
||||
list($year, $month, $day, $hour, $min, $meridian) = $newTime;
|
||||
}
|
||||
|
@ -2505,15 +2509,8 @@ class FormHelper extends AppHelper {
|
|||
if (!empty($timeFormat)) {
|
||||
$time = explode(':', $days[1]);
|
||||
|
||||
if ($time[0] >= 12 && $timeFormat == 12) {
|
||||
if ($time[0] >= 12) {
|
||||
$meridian = 'pm';
|
||||
} elseif ($time[0] === '00' && $timeFormat == 12) {
|
||||
$time[0] = 12;
|
||||
} elseif ($time[0] >= 12) {
|
||||
$meridian = 'pm';
|
||||
}
|
||||
if ($time[0] == 0 && $timeFormat == 12) {
|
||||
$time[0] = 12;
|
||||
}
|
||||
$hour = $min = null;
|
||||
if (isset($time[1])) {
|
||||
|
|
Loading…
Add table
Reference in a new issue