public function RegionTimezone::__construct in Geo Time Zone 8.2
Same name and namespace in other branches
- 8.3 src/RegionTimezone.php \Drupal\geotimezone\RegionTimezone::__construct()
- 6.2 src/RegionTimezone.php \Drupal\geotimezone\RegionTimezone::__construct()
- 7.2 src/RegionTimezone.php \Drupal\geotimezone\RegionTimezone::__construct()
RegionTimezone constructor.
Parameters
array $location: Location details in associative array with expected array keys of: regionCode region countryCode Required keys to have values are: countryCode and either of regionCode or region.
File
- src/
RegionTimezone.php, line 55 - Contains \Drupal\geotimezone\RegionTimezone.
Class
- RegionTimezone
- Holds the list of time zone based on region code and region name.
Namespace
Drupal\geotimezoneCode
public function __construct($location) {
if (isset($location['countryCode']) && !empty($location['countryCode'])) {
if (isset($location['regionCode']) && !empty($location['regionCode'])) {
static::$listCode = $this
->loadRegionCodeList();
$this->identifier = static::$listCode[$location['countryCode']][$location['regionCode']];
}
elseif (isset($location['region']) && !empty($location['region'])) {
static::$listName = $this
->loadRegionNameList();
$this->identifier = static::$listName[$location['countryCode']][$location['region']];
}
if (!empty($this->identifier)) {
// Convert to time zone offset
$time = new \DateTime('now', new \DateTimeZone($this->identifier));
$this->offset = $time
->format('P');
}
}
else {
$this->identifier = NULL;
$this->offset = NULL;
}
}