You are here

public static function Utility::getTimeZone in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getTimeZone()

Returns the timezone for a query.

There's a fallback mechanism to get the time zone: 1. time zone configured for the index 2. the current user's time zone 3. site default time zone 4. storage time zone (UTC)

Parameters

\Drupal\search_api\IndexInterface $index: The Solr index.

Return value

string The timezone.

1 call to Utility::getTimeZone()
SearchApiSolrBackend::applySearchWorkarounds in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Apply workarounds for special Solr versions before searching.

File

src/Utility/Utility.php, line 980

Class

Utility
Provides various helper functions for Solr backends.

Namespace

Drupal\search_api_solr\Utility

Code

public static function getTimeZone(IndexInterface $index) : string {
  $settings = self::getIndexSolrSettings($index);
  $system_date = \Drupal::config('system.date');
  $timezone = '';
  if ($settings['advanced']['timezone']) {
    $timezone = $settings['advanced']['timezone'];
  }
  else {
    if ($system_date
      ->get('timezone.user.configurable')) {
      $timezone = \Drupal::currentUser()
        ->getAccount()
        ->getTimeZone();
    }
  }
  if (!$timezone) {
    $timezone = $system_date
      ->get('timezone.default') ?: date_default_timezone_get();
  }
  return $timezone ?: DateTimeItemInterface::STORAGE_TIMEZONE;
}