From 823d71ced9b4947b1a5a5ade7245d521ed490061 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 7 Jun 2016 15:17:49 +0200 Subject: * renaming php directory --- app/frontend/dto/TimezoneDTO.php | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 app/frontend/dto/TimezoneDTO.php (limited to 'app/frontend/dto/TimezoneDTO.php') diff --git a/app/frontend/dto/TimezoneDTO.php b/app/frontend/dto/TimezoneDTO.php new file mode 100644 index 0000000..e4078e6 --- /dev/null +++ b/app/frontend/dto/TimezoneDTO.php @@ -0,0 +1,46 @@ +Name = $tz->getName(); + $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; + } + +} + +?> -- cgit v1.2.3