Skip to content
Snippets Groups Projects
Commit 2c4a6d80 authored by Ivan Doroshenko's avatar Ivan Doroshenko Committed by Owen Bush
Browse files

Issue #3283128 by Matroskeen, owenbush: Use date.formatter service to format date values

parent 736eaa1f
No related branches found
No related tags found
1 merge request!34Issue #3283128: Use date.formatter service to format date values.
...@@ -4,6 +4,7 @@ namespace Drupal\recurring_events\Plugin\views\field; ...@@ -4,6 +4,7 @@ namespace Drupal\recurring_events\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow; use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Field handler to show the start date of an event series. * Field handler to show the start date of an event series.
...@@ -14,6 +15,22 @@ use Drupal\views\ResultRow; ...@@ -14,6 +15,22 @@ use Drupal\views\ResultRow;
*/ */
class EventSeriesStartDate extends FieldPluginBase { class EventSeriesStartDate extends FieldPluginBase {
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->dateFormatter = $container->get('date.formatter');
return $instance;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -33,7 +50,7 @@ class EventSeriesStartDate extends FieldPluginBase { ...@@ -33,7 +50,7 @@ class EventSeriesStartDate extends FieldPluginBase {
if (!empty($event_start)) { if (!empty($event_start)) {
$format = \Drupal::config('recurring_events.eventseries.config')->get('date_format'); $format = \Drupal::config('recurring_events.eventseries.config')->get('date_format');
$start_date = $event_start->setTimezone($timezone)->format($format); $start_date = $this->dateFormatter->format($event_start->getTimestamp(), 'custom', $format, $timezone->getName());
} }
return $start_date; return $start_date;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment