You are here

public static function MatomoBase::formatDateRange in Dashboards with Layout Builder 2.0.x

Same name and namespace in other branches
  1. 8 modules/dashboards_matomo/src/Plugin/Dashboard/MatomoBase.php \Drupal\dashboards_matomo\Plugin\Dashboard\MatomoBase::formatDateRange()

Helper function for short date ranges.

Parameters

int $d1: Date start.

int $d2: Date end.

Return value

string Formatted date.

1 call to MatomoBase::formatDateRange()
MatomoBase::query in modules/dashboards_matomo/src/Plugin/Dashboard/MatomoBase.php
Helper function for query matomo.

File

modules/dashboards_matomo/src/Plugin/Dashboard/MatomoBase.php, line 219

Class

MatomoBase
Base class for matomo plugins.

Namespace

Drupal\dashboards_matomo\Plugin\Dashboard

Code

public static function formatDateRange($d1, $d2) {
  $d1 = new DateTime($d1);
  $d2 = new DateTime($d2);
  if ($d1
    ->format('Y-m-d') === $d2
    ->format('Y-m-d')) {
    return $d1
      ->format('d.m');
  }
  elseif ($d1
    ->format('Y-m') === $d2
    ->format('Y-m')) {
    return $d1
      ->format('d') . $d2
      ->format(' – d.m');
  }
  elseif ($d1
    ->format('Y') === $d2
    ->format('Y')) {
    return $d1
      ->format('d.m') . $d2
      ->format(' – d.m');
  }
  else {
    return $d1
      ->format('d.m.Y') . $d2
      ->format(' – d.m.Y');
  }
}