Issue #2511854 by NickWilde, cilefen: Datetime select list uses PHP non-OOP datetime functions
parent
9f521c8dc5
commit
200e1b885c
|
@ -335,10 +335,10 @@ class Datelist extends DateElementBase {
|
|||
protected static function incrementRound(&$date, $increment) {
|
||||
// Round minutes and seconds, if necessary.
|
||||
if ($date instanceOf DrupalDateTime && $increment > 1) {
|
||||
$day = intval(date_format($date, 'j'));
|
||||
$hour = intval(date_format($date, 'H'));
|
||||
$second = intval(round(intval(date_format($date, 's')) / $increment) * $increment);
|
||||
$minute = intval(date_format($date, 'i'));
|
||||
$day = intval($date->format('j'));
|
||||
$hour = intval($date->format('H'));
|
||||
$second = intval(round(intval($date->format('s')) / $increment) * $increment);
|
||||
$minute = intval($date->format('i'));
|
||||
if ($second == 60) {
|
||||
$minute += 1;
|
||||
$second = 0;
|
||||
|
@ -348,12 +348,12 @@ class Datelist extends DateElementBase {
|
|||
$hour += 1;
|
||||
$minute = 0;
|
||||
}
|
||||
date_time_set($date, $hour, $minute, $second);
|
||||
$date->setTime($hour, $minute, $second);
|
||||
if ($hour == 24) {
|
||||
$day += 1;
|
||||
$year = date_format($date, 'Y');
|
||||
$month = date_format($date, 'n');
|
||||
date_date_set($date, $year, $month, $day);
|
||||
$year = $date->format('Y');
|
||||
$month = $date->format('n');
|
||||
$date->setDate($year, $month, $day);
|
||||
}
|
||||
}
|
||||
return $date;
|
||||
|
|
|
@ -438,6 +438,46 @@ class DateTimeFieldTest extends WebTestBase {
|
|||
$this->assertOptionSelected("edit-$field_name-0-value-hour", '5', 'Correct hour selected.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-minute", '15', 'Correct minute selected.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-ampm", 'am', 'Correct ampm selected.');
|
||||
|
||||
// Test the widget using increment other than 1 and 24 hour mode.
|
||||
entity_get_form_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'default')
|
||||
->setComponent($field_name, array(
|
||||
'type' => 'datetime_datelist',
|
||||
'settings' => array(
|
||||
'increment' => 15,
|
||||
'date_order' => 'YMD',
|
||||
'time_type' => '24',
|
||||
),
|
||||
))
|
||||
->save();
|
||||
\Drupal::entityManager()->clearCachedFieldDefinitions();
|
||||
|
||||
// Display creation form.
|
||||
$this->drupalGet('entity_test/add');
|
||||
|
||||
// Other elements are unaffected by the changed settings.
|
||||
$this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element found.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-hour", '', 'No hour selected.');
|
||||
$this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-ampm\"]", NULL, 'AMPM element not found.');
|
||||
|
||||
// Submit a valid date and ensure it is accepted.
|
||||
$date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 17, 'minute' => 15);
|
||||
|
||||
$edit = array();
|
||||
foreach ($date_value as $part => $value) {
|
||||
$edit["{$field_name}[0][value][$part]"] = $value;
|
||||
}
|
||||
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
|
||||
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-year", '2012', 'Correct year selected.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-month", '12', 'Correct month selected.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-day", '31', 'Correct day selected.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-hour", '17', 'Correct hour selected.');
|
||||
$this->assertOptionSelected("edit-$field_name-0-value-minute", '15', 'Correct minute selected.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue