summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-16 01:11:03 +0100
committeremkael <emkael@tlen.pl>2016-03-16 01:11:03 +0100
commit81890fab8952f6ee9dcb1f3c0a577472cf7c4fd6 (patch)
tree4b3ed536f83f0877e1be6b89cd687d9c0d44c727 /app
parentaa633881b411c81009d4e1d394d30c950da9c70f (diff)
* respecting timezone preference for events
Diffstat (limited to 'app')
-rw-r--r--app/php/dto/EventDTO.php4
-rw-r--r--app/php/dto/TimezoneDTO.php22
-rw-r--r--app/php/user/DbUser.php10
3 files changed, 35 insertions, 1 deletions
diff --git a/app/php/dto/EventDTO.php b/app/php/dto/EventDTO.php
index 4a16505..b1042b1 100644
--- a/app/php/dto/EventDTO.php
+++ b/app/php/dto/EventDTO.php
@@ -15,7 +15,9 @@ class EventDTO {
$this->Location = $event->Location;
$utc = new DateTimeZone('UTC');
- $targetTz = new DateTimeZone(date_default_timezone_get());
+ $targetTz = new DateTimeZone(
+ Prado::getApplication()->getUser()->getTimezonePreference()->Name
+ );
$beginDate = new DateTime($event->BeginDate, $utc);
$endDate = new DateTime($event->EndDate, $utc);
if ($event->AllDay) {
diff --git a/app/php/dto/TimezoneDTO.php b/app/php/dto/TimezoneDTO.php
new file mode 100644
index 0000000..4bb57f2
--- /dev/null
+++ b/app/php/dto/TimezoneDTO.php
@@ -0,0 +1,22 @@
+<?php
+
+class TimezoneDTO {
+
+ public $Label;
+ public $Name;
+ public $Offset;
+ public $OffsetHours;
+ public $OffsetMinutes;
+
+ public function __construct($name) {
+ $tz = new DateTimeZone($name);
+ $this->Name = $tz->getName();
+ $this->Offset = $tz->getOffset(new DateTime());
+ $this->OffsetHours = $this->Offset / 3600;
+ $this->OffsetMinutes = $this->Offset % 3600 / 60;
+ $this->Label = sprintf('UTC%+03d:%02d %s', $this->OffsetHours, $this->OffsetMinutes, $this->Name);
+ }
+
+}
+
+?>
diff --git a/app/php/user/DbUser.php b/app/php/user/DbUser.php
index bb6f78e..c3b441b 100644
--- a/app/php/user/DbUser.php
+++ b/app/php/user/DbUser.php
@@ -3,6 +3,7 @@
Prado::using('System.Security.TDbUserManager');
Prado::using('Application.model.User');
Prado::using('Application.model.Calendar');
+Prado::using('Application.dto.TimezoneDTO');
class DbUser extends TDbUser {
@@ -62,6 +63,15 @@ class DbUser extends TDbUser {
}
}
+ public function getTimezonePreference() {
+ if (!$this->IsGuest) {
+ try {
+ return new TimezoneDTO($this->DbRecord->Timezone);
+ } catch(Exception $e) {}
+ }
+ return new TimezoneDTO(date_default_timezone_get());
+ }
+
public static function generatePassword($password) {
return password_hash($password, PASSWORD_DEFAULT);
}