diff options
author | emkael <emkael@tlen.pl> | 2016-05-13 13:40:17 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-13 13:40:17 +0200 |
commit | 0df58521beb5d7154a09bc8bb3abe83b948996c8 (patch) | |
tree | 461616ea4c87634ca106946a1e8de0ff606e443e /app/php/dto | |
parent | 64c5f5544fe64fb314ef8602eb3b702bc35d0e11 (diff) |
* tiemzone-awareness and storing intermediate information in EventDTO
Diffstat (limited to 'app/php/dto')
-rw-r--r-- | app/php/dto/EventDTO.php | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/app/php/dto/EventDTO.php b/app/php/dto/EventDTO.php index 4131210..8f5cdf5 100644 --- a/app/php/dto/EventDTO.php +++ b/app/php/dto/EventDTO.php @@ -11,29 +11,53 @@ class EventDTO { public $Location; public $Calendar; - public function loadRecord(Entry $event, array $calendars) { - $this->Name = $event->Name; - $this->Location = $event->Location; + private $_utc; + private $_targetTZ; - $utc = new DateTimeZone('UTC'); - $targetTz = new DateTimeZone( - UserFacade::getInstance()->getTimezonePreference( + public function __construct(TimezoneDTO $tz = NULL) { + $this->_utc = new DateTimeZone('UTC'); + $this->_targetTZ = new DateTimeZone( + $tz + ? $tz->Name + : UserFacade::getInstance()->getTimezonePreference( Prado::getApplication()->getUser() )->Name ); - $beginDate = new DateTime($event->BeginDate, $utc); - $endDate = new DateTime($event->EndDate, $utc); + } + + private $_beginDate; + protected function getBeginDate(Entry $event) { + if (!$this->_beginDate) { + $this->_beginDate = new DateTime($event->BeginDate, $this->_utc); + } + return $this->_beginDate; + } + + private $_endDate; + protected function getEndDate(Entry $event) { + if (!$this->_endDate) { + $this->_endDate = new DateTime($event->EndDate, $this->_utc); + if ($event->AllDay) { + $this->_endDate = $this->_endDate->modify('-1 day'); + } + } + return $this->_endDate; + } + + public function loadRecord(Entry $event, array $calendars) { + $this->Name = $event->Name; + $this->Location = $event->Location; + if ($event->AllDay) { - $endDate = $endDate->modify('-1 day'); - $this->DateString = $beginDate->format('Y-m-d'); - if ($beginDate != $endDate) { + $this->DateString = $this->getBeginDate($event)->format('Y-m-d'); + if ($this->getBeginDate($event) != $this->getEndDate($event)) { $this->DateString .= sprintf( ' - %s', - $endDate->format('Y-m-d') + $this->getEndDate($event)->format('Y-m-d') ); } } else { - $beginDate = $beginDate->setTimezone($targetTz); + $beginDate = $this->getBeginDate($event)->setTimezone($this->_targetTZ); $this->DateString = $beginDate->format('Y-m-d H:i'); } @@ -44,7 +68,9 @@ class EventDTO { } ); $this->Calendar = new CalendarDTO(); - $this->Calendar->loadRecord($calendars ? array_values($calendars)[0] : $event->Calendar); + $this->Calendar->loadRecord( + $calendars ? array_values($calendars)[0] : $event->Calendar + ); } public static function __compare(EventDTO $ev1, EventDTO $ev2) { |