You are here

public function CountryTimezone::__construct in Geo Time Zone 8.3

Same name and namespace in other branches
  1. 8.2 src/CountryTimezone.php \Drupal\geotimezone\CountryTimezone::__construct()
  2. 6.2 src/CountryTimezone.php \Drupal\geotimezone\CountryTimezone::__construct()
  3. 7.2 src/CountryTimezone.php \Drupal\geotimezone\CountryTimezone::__construct()

CountryTimezone constructor.

Parameters

array $location: Location details in associative array with expected array keys of 'countryCode'.

File

src/CountryTimezone.php, line 45
Contains \Drupal\geotimezone\CountryTimezone.

Class

CountryTimezone
Holds the list of time zone based on country code.

Namespace

Drupal\geotimezone

Code

public function __construct($location) {
  if (isset($location['countryCode']) && !empty($location['countryCode'])) {
    static::$list = $this
      ->loadList();
    $this->identifier = static::$list[$location['countryCode']];
    $this->identifier = array_values($this->identifier);
    if (!empty($this->identifier)) {

      // Convert to time zone offset
      foreach ($this->identifier as $identifier) {
        $time = new \DateTime('now', new \DateTimeZone($identifier));
        $this->offset[] = $time
          ->format('P');
      }
    }
  }
  else {
    $this->identifier = NULL;
    $this->offset = NULL;
  }
}