You are here

protected function DateRecurModularSierraWidget::parseTimeInput in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::parseTimeInput()
  2. 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::parseTimeInput()

Parses raw input from a time field.

Inspired by \Drupal\Core\Datetime\Element\Datetime::valueCallback, exists because plain 'time' fields do not have value callbacks.

Parameters

string $input: Input from a time field.

Return value

\Drupal\Core\Datetime\DrupalDateTime|null A date object, or NULL if input was invalid. The date portion of this object should be ignored.

1 call to DateRecurModularSierraWidget::parseTimeInput()
DateRecurModularSierraWidget::formElement in src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php, line 989

Class

DateRecurModularSierraWidget
Date recur sierra widget.

Namespace

Drupal\date_recur_modular\Plugin\Field\FieldWidget

Code

protected function parseTimeInput(string $input) : ?DrupalDateTime {
  if (strlen($input) == 5) {
    $input .= ':00';
  }
  $timeFormat = DateFormat::load('html_time')
    ->getPattern();
  try {
    return DrupalDateTime::createFromFormat($timeFormat, $input);
  } catch (\Exception $e) {
    return NULL;
  }
}