You are here

protected function BaseMoment::getMoment in Twig Extender 4.x

Same name and namespace in other branches
  1. 8.4 modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment::getMoment()
  2. 8.2 modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment::getMoment()
  3. 8.3 modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php \Drupal\twig_extender_extras\Plugin\TwigPlugin\BaseMoment::getMoment()

Get moment library.

Parameters

mixed $date: String or DateTime Object.

string $timezone: Override timezone.

4 calls to BaseMoment::getMoment()
MomentCalendar::moment in modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentCalendar.php
Return date formatted in a relative date.
MomentDifference::moment in modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentDifference.php
Get a difference between two dates.
MomentFormat::moment in modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentFormat.php
Format a date with moment php.
MomentOperation::moment in modules/twig_extender_extras/src/Plugin/TwigPlugin/MomentOperation.php
Possibility to add or substract days or weeks ...

File

modules/twig_extender_extras/src/Plugin/TwigPlugin/BaseMoment.php, line 56

Class

BaseMoment
Base class for moment plugins.

Namespace

Drupal\twig_extender_extras\Plugin\TwigPlugin

Code

protected function getMoment($date, $timezone = NULL) {
  if ($timezone === NULL) {
    $timezone = $this
      ->getDefaultTimezone();
  }
  Moment::setLocale($this
    ->getLocale());
  if ($date === NULL) {
    return (new Moment())
      ->setTimezone($timezone);
  }
  if (is_numeric($date)) {
    return (new Moment())
      ->setTimestamp($date)
      ->setTimezone($timezone);
  }
  if (is_a($date, '\\Moment\\Moment')) {
    return $date;
  }
  return new Moment($date, $timezone);
}