You are here

private function ScheduledPublishGenericFormatter::parseDate in Scheduled Publish 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/ScheduledPublishGenericFormatter.php \Drupal\scheduled_publish\Plugin\Field\FieldFormatter\ScheduledPublishGenericFormatter::parseDate()

Parameters

string $strDateTime:

string $strDateFormat:

Return value

\DateTime

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to ScheduledPublishGenericFormatter::parseDate()
ScheduledPublishGenericFormatter::parseData in src/Plugin/Field/FieldFormatter/ScheduledPublishGenericFormatter.php

File

src/Plugin/Field/FieldFormatter/ScheduledPublishGenericFormatter.php, line 202

Class

ScheduledPublishGenericFormatter
Plugin implementation of the 'scheduled_publish_generic_formatter' formatter.

Namespace

Drupal\scheduled_publish\Plugin\Field\FieldFormatter

Code

private function parseDate(string $strDateTime, string $strDateFormat) : string {
  $dateFormat = $this->entityTypeManager
    ->getStorage('date_format')
    ->load($strDateFormat);
  if ($dateFormat !== NULL) {
    $pattern = $dateFormat
      ->getPattern();
    $drupalDateTime = DrupalDateTime::createFromFormat(ScheduledPublish::DATETIME_STORAGE_FORMAT, $strDateTime);
    return $drupalDateTime
      ->format($pattern);
  }
  $this->logger
    ->error($this
    ->t('Date format: "' . $this
    ->getSetting('date_format') . '" could not be found!'));
  return NULL;
}