diff options
author | emkael <emkael@tlen.pl> | 2016-05-13 11:24:34 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-13 11:24:34 +0200 |
commit | 68f962ed70ea9e5aae93cca956b9ec11c5150c3c (patch) | |
tree | 8c1b991e38a958f2089b378f537a1abf6f9a1267 | |
parent | 3abcdafe76817b258c726c480fd021667ad84d4b (diff) |
* location and calendar information for timezone
-rw-r--r-- | app/php/dto/TimezoneDTO.php | 19 | ||||
l--------- | app/php/dto/weekdays.json | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/app/php/dto/TimezoneDTO.php b/app/php/dto/TimezoneDTO.php index d80d4dd..5f89cca 100644 --- a/app/php/dto/TimezoneDTO.php +++ b/app/php/dto/TimezoneDTO.php @@ -7,6 +7,8 @@ class TimezoneDTO { public $Offset; public $OffsetHours; public $OffsetMinutes; + public $Location; + public $FirstDayOfTheWeek; public function __construct($name) { $tz = new DateTimeZone($name); @@ -14,9 +16,26 @@ class TimezoneDTO { $this->Offset = $tz->getOffset(new DateTime()); $this->OffsetHours = $this->Offset / 3600; $this->OffsetMinutes = $this->Offset % 3600 / 60; + $this->Location = $tz->getLocation()['country_code']; + $this->FirstDayOfTheWeek = $this->_getFirstDayOfTheWeek(); $this->Label = sprintf('UTC%+03d:%02d %s', $this->OffsetHours, $this->OffsetMinutes, $this->Name); } + private function _getFirstDayOfTheWeek() { + $dayMapping = json_decode( + file_get_contents( + Prado::getPathOfNamespace('Application.dto.weekdays', '.json') + ), + TRUE + ); + if ($this->Location && isset($dayMapping[$this->Location])) { + return ucfirst($dayMapping[$this->Location]); + } + return ucfirst($dayMapping['001']); + } + + + public static function __compare(TimezoneDTO $tz1, TimezoneDTO $tz2) { $diff = $tz1->Offset - $tz2->Offset; return ($diff == 0) ? strcmp($tz1->Name, $tz2->Name) : $diff; diff --git a/app/php/dto/weekdays.json b/app/php/dto/weekdays.json new file mode 120000 index 0000000..325c801 --- /dev/null +++ b/app/php/dto/weekdays.json @@ -0,0 +1 @@ +../../../config/weekdays.json
\ No newline at end of file |