diff --git a/core/lib/Drupal/Core/Datetime/Element/Datetime.php b/core/lib/Drupal/Core/Datetime/Element/Datetime.php index 44a3949..b52e28e 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datetime.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php @@ -247,12 +247,17 @@ public static function processDatetime(&$element, FormStateInterface $form_state $html5_min->setDate($range[0], 1, 1)->setTime(0, 0, 0); $html5_max = clone($date); $html5_max->setDate($range[1], 12, 31)->setTime(23, 59, 59); - - $extra_attributes += array( - 'min' => $html5_min->format($date_format, $format_settings), - 'max' => $html5_max->format($date_format, $format_settings), - ); } + else { + $range = static::datetimeRangeYears($element['#date_year_range']); + $html5_min = DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $range[0] . '-01-01 00:00:00'); + $html5_max = DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $range[1] . '-12-31 23:59:59'); + } + + $extra_attributes += array( + 'min' => $html5_min->format($date_format, $format_settings), + 'max' => $html5_max->format($date_format, $format_settings), + ); $element['date'] = array( '#type' => 'date', diff --git a/core/modules/system/src/Tests/Form/DatetimeTest.php b/core/modules/system/src/Tests/Form/DatetimeTest.php index 782f361..1f207d8 100644 --- a/core/modules/system/src/Tests/Form/DatetimeTest.php +++ b/core/modules/system/src/Tests/Form/DatetimeTest.php @@ -43,12 +43,16 @@ function testFormDatetimeMinMax() { 'datetime[time]' => '01:02:03', ]; - // OK, these are the default values. - $this->drupalPostForm(NULL, $edit, 'Submit'); - $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1900-01-01" and @max="2050-12-31"]', '1776-07-14', 'Found input[@type="date" and @min="1900-01-01" and @max="2050-12-31"]'); - - // This makes no sense. + $this->drupalPostForm('form-test/datetime', $edit, 'Submit'); $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1776-01-01" and @max="2050-12-31"]', '1776-07-14', 'Found input[@type="date" and @min="1776-01-01" and @max="2050-12-31"]'); + + $edit = [ + 'datetime[date]' => '2134-07-14', + 'datetime[time]' => '01:02:03', + ]; + + $this->drupalPostForm('form-test/datetime', $edit, 'Submit'); + $this->assertFieldByXPath('//div[@id="edit-datetime"]//input[@type="date" and @min="1900-01-01" and @max="2134-12-31"]', '2134-07-14', 'Found input[@type="date" and @min="1900-01-01" and @max="2134-07-14"]'); } }