You are here

public function MomentCalendar::moment in Twig Extender 8.2

Same name and namespace in other branches
  1. 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentCalendar.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentCalendar::moment()
  2. 8.3 modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentCalendar.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentCalendar::moment()
  3. 4.x modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentCalendar.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\MomentCalendar::moment()

Return date formatted in a relative date.

Parameters

string $date: The element array whose children are to be identified. Passed by reference.

string $timezone: Boolean to indicate whether the children should be sorted by weight.

Return value

array Array for render.

Throws

\Exception

See also

https://github.com/fightbulc/moment.php

File

modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentCalendar.php, line 34

Class

MomentCalendar
Provide helper methods for Drupal render elements.

Namespace

Drupal\twig_extender_extras\Plugin\TwigPlugin

Code

public function moment($date, $timezone = NULL) {
  $moment = $this
    ->getMoment($date, $timezone);
  $build = [
    '#cache' => [
      'contexts' => [
        'languages',
        'timezone',
      ],
    ],
    '#markup' => $moment
      ->calendar(),
  ];
  return $build;
}