You are here

protected function DateTimeFieldMapping::convertTimestamp in Webform Content Creator 3.x

Convert timestamp value according to field type.

Parameters

int $value: Original datetime value.

FieldDefinitionInterface $field_definition: Entity field.

Return value

string Converted value.

1 call to DateTimeFieldMapping::convertTimestamp()
DateTimeFieldMapping::mapEntityField in src/Plugin/WebformContentCreator/FieldMapping/DateTimeFieldMapping.php
Use a single mapping to set an entity field value.

File

src/Plugin/WebformContentCreator/FieldMapping/DateTimeFieldMapping.php, line 61

Class

DateTimeFieldMapping
Provides a datetime field mapping.

Namespace

Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMapping

Code

protected function convertTimestamp($value, FieldDefinitionInterface $field_definition) {
  $date_time = new DrupalDateTime($value, 'UTC');
  $date_type = $field_definition
    ->getSettings()['datetime_type'];
  if ($date_type === 'datetime') {
    $result = \Drupal::service('date.formatter')
      ->format($date_time
      ->getTimestamp(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, 'UTC');
  }
  else {
    $result = \Drupal::service('date.formatter')
      ->format($date_time
      ->getTimestamp(), 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT, 'UTC');
  }
  return $result;
}