mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1165 from cakephp/master-year-range
Fix FormHelper year range for ranges outside of 1901-2038
This commit is contained in:
commit
69f416da1e
2 changed files with 75 additions and 7 deletions
|
@ -5845,6 +5845,23 @@ class FormHelperTest extends CakeTestCase {
|
|||
'*/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request->data['Project']['release'] = '2050-02-10';
|
||||
$result = $this->Form->month('Project.release');
|
||||
|
||||
$expected = array(
|
||||
array('select' => array('name' => 'data[Project][release][month]', 'id' => 'ProjectReleaseMonth')),
|
||||
array('option' => array('value' => '')),
|
||||
'/option',
|
||||
array('option' => array('value' => '01')),
|
||||
'January',
|
||||
'/option',
|
||||
array('option' => array('value' => '02', 'selected' => 'selected')),
|
||||
'February',
|
||||
'/option',
|
||||
'*/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5933,6 +5950,28 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->request->data['Project']['release'] = '2050-10-10';
|
||||
$result = $this->Form->day('Project.release');
|
||||
|
||||
$expected = array(
|
||||
array('select' => array('name' => 'data[Project][release][day]', 'id' => 'ProjectReleaseDay')),
|
||||
array('option' => array('value' => '')),
|
||||
'/option',
|
||||
array('option' => array('value' => '01')),
|
||||
'1',
|
||||
'/option',
|
||||
array('option' => array('value' => '02')),
|
||||
'2',
|
||||
'/option',
|
||||
$daysRegex,
|
||||
array('option' => array('value' => '10', 'selected' => 'selected')),
|
||||
'10',
|
||||
'/option',
|
||||
$daysRegex,
|
||||
'/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6103,6 +6142,26 @@ class FormHelperTest extends CakeTestCase {
|
|||
$thisHour = date('H');
|
||||
$optValue = date('G');
|
||||
$this->assertRegExp('/<option value="' . $thisHour . '" selected="selected">' . $optValue . '<\/option>/', $result);
|
||||
|
||||
$this->Form->request->data['Model']['field'] = '2050-10-10 01:12:32';
|
||||
$result = $this->Form->hour('Model.field', true);
|
||||
$expected = array(
|
||||
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
|
||||
array('option' => array('value' => '')),
|
||||
'/option',
|
||||
array('option' => array('value' => '00')),
|
||||
'0',
|
||||
'/option',
|
||||
array('option' => array('value' => '01', 'selected' => 'selected')),
|
||||
'1',
|
||||
'/option',
|
||||
array('option' => array('value' => '02')),
|
||||
'2',
|
||||
'/option',
|
||||
$hoursRegex,
|
||||
'/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6308,6 +6367,14 @@ class FormHelperTest extends CakeTestCase {
|
|||
$result = $matches[1];
|
||||
$expected = range(2050, date('Y') - 20);
|
||||
$this->assertEquals($result, $expected);
|
||||
|
||||
$this->Form->request->data['Project']['release'] = '1881-10-10';
|
||||
$result = $this->Form->year('Project.release', 1890, 1900);
|
||||
preg_match_all('/<option value="([\d]+)"/', $result, $matches);
|
||||
|
||||
$result = $matches[1];
|
||||
$expected = range(1900, 1881);
|
||||
$this->assertEquals($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2077,7 +2077,7 @@ class FormHelper extends AppHelper {
|
|||
$attributes = $this->_dateTimeSelected('day', $fieldName, $attributes);
|
||||
|
||||
if (strlen($attributes['value']) > 2) {
|
||||
$attributes['value'] = date('d', strtotime($attributes['value']));
|
||||
$attributes['value'] = date_create($attributes['value'])->format('d');
|
||||
} elseif ($attributes['value'] === false) {
|
||||
$attributes['value'] = null;
|
||||
}
|
||||
|
@ -2123,7 +2123,7 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
if (strlen($attributes['value']) > 4 || $attributes['value'] === 'now') {
|
||||
$attributes['value'] = date('Y', strtotime($attributes['value']));
|
||||
$attributes['value'] = date_create($attributes['value'])->format('Y');
|
||||
} elseif ($attributes['value'] === false) {
|
||||
$attributes['value'] = null;
|
||||
}
|
||||
|
@ -2159,7 +2159,7 @@ class FormHelper extends AppHelper {
|
|||
$attributes = $this->_dateTimeSelected('month', $fieldName, $attributes);
|
||||
|
||||
if (strlen($attributes['value']) > 2) {
|
||||
$attributes['value'] = date('m', strtotime($attributes['value']));
|
||||
$attributes['value'] = date_create($attributes['value'])->format('m');
|
||||
} elseif ($attributes['value'] === false) {
|
||||
$attributes['value'] = null;
|
||||
}
|
||||
|
@ -2195,10 +2195,11 @@ class FormHelper extends AppHelper {
|
|||
$attributes = $this->_dateTimeSelected('hour', $fieldName, $attributes);
|
||||
|
||||
if (strlen($attributes['value']) > 2) {
|
||||
$Date = new DateTime($attributes['value']);
|
||||
if ($format24Hours) {
|
||||
$attributes['value'] = date('H', strtotime($attributes['value']));
|
||||
$attributes['value'] = $Date->format('H');
|
||||
} else {
|
||||
$attributes['value'] = date('g', strtotime($attributes['value']));
|
||||
$attributes['value'] = $Date->format('g');
|
||||
}
|
||||
} elseif ($attributes['value'] === false) {
|
||||
$attributes['value'] = null;
|
||||
|
@ -2234,7 +2235,7 @@ class FormHelper extends AppHelper {
|
|||
$attributes = $this->_dateTimeSelected('min', $fieldName, $attributes);
|
||||
|
||||
if (strlen($attributes['value']) > 2) {
|
||||
$attributes['value'] = date('i', strtotime($attributes['value']));
|
||||
$attributes['value'] = date_create($attributes['value'])->format('i');
|
||||
} elseif ($attributes['value'] === false) {
|
||||
$attributes['value'] = null;
|
||||
}
|
||||
|
@ -2301,7 +2302,7 @@ class FormHelper extends AppHelper {
|
|||
$attributes['value'] = date('a');
|
||||
}
|
||||
} else {
|
||||
$attributes['value'] = date('a', strtotime($value));
|
||||
$attributes['value'] = date_create($attributes['value'])->format('a');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue