You are here

public static function SmartDateWidgetBase::remapDatetime in Smart Date 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::remapDatetime()
  2. 3.0.x src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::remapDatetime()
  3. 3.1.x src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::remapDatetime()
  4. 3.2.x src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::remapDatetime()
  5. 3.3.x src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::remapDatetime()
  6. 3.4.x src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::remapDatetime()

Conditionally convert a DrupalDateTime object to a timestamp.

Parameters

\Drupal\Core\Datetime\DrupalDateTime|null $time: The time to be converted.

DateTimezone|null $timezone: An optional timezone to use for conversion.

2 calls to SmartDateWidgetBase::remapDatetime()
SmartDateWidgetBase::createWidget in src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php
Helper method to create SmartDate element.
SmartDateWidgetBase::smartGetTimestamp in src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php
Conditionally convert a DrupalDateTime object to a timestamp.

File

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

Class

SmartDateWidgetBase
Base class for the 'smartdate_*' widgets.

Namespace

Drupal\smart_date\Plugin\Field\FieldWidget

Code

public static function remapDatetime($time, $timezone = NULL) {
  if (empty($time)) {
    return '';
  }
  $time = new DrupalDateTime($time
    ->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT), $timezone);
  return $time;
}