You are here

protected function SmartDateWidgetBase::createNormalizedDefaultValue in Smart Date 3.4.x

Creates a default value with the seconds set to zero.

Parameters

mixed $date: The configured default.

string $timezone: A configured timezone for the field, if set.

Return value

\Drupal\Core\Datetime\DrupalDateTime A date object for use as a default value in a field widget.

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

File

src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php, line 573

Class

SmartDateWidgetBase
Base class for the 'smartdate_*' widgets.

Namespace

Drupal\smart_date\Plugin\Field\FieldWidget

Code

protected function createNormalizedDefaultValue($date, $timezone) {
  $date = $this
    ->createDefaultValue($date, $timezone);

  // Resert seconds, so they will always fall on :00.
  $date
    ->sub(new \DateInterval('PT' . $date
    ->format('s') . 'S'));
  return $date;
}