You are here

public function MomentDifference::moment in Twig Extender 8.2

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

Get a difference between two dates.

Parameters

string $from: Start date.

mixed $to: Date is relative to.

mixed $operation: Operation. Could be: relative|direction|seconds|minutes|hours|days|weeks|months|years.

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

Return value

array String for render.

See also

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

File

modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentDifference.php, line 36

Class

MomentDifference
Provide helper methods for Drupal render elements.

Namespace

Drupal\twig_extender_extras\Plugin\TwigPlugin

Code

public function moment($from, $to = NULL, $operation = 'direction', $timezone = NULL) {
  $moment = $this
    ->getMoment($to, $timezone);
  $from = $this
    ->getMoment($from, $timezone);
  $funcCall = 'get' . ucfirst($operation);
  return $moment
    ->from($from
    ->format())
    ->{$funcCall}();
}