summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2011-09-28 11:49:37 +0000
committerthomascube <thomas@roundcube.net>2011-09-28 11:49:37 +0000
commit65082b3adbfaa04c4aff7c41147bb43e34941106 (patch)
tree193989ac4b845ed55db352c7790f5f10fab9f347 /program
parent1991b77ace5fe11fc897ac4795c9f9771f6ae57c (diff)
Distinguish standard timezone offset and DST of client
Diffstat (limited to 'program')
-rw-r--r--program/include/main.inc2
-rw-r--r--program/include/rcmail.php2
-rw-r--r--program/include/rcube_config.php25
-rwxr-xr-xprogram/include/rcube_template.php2
-rw-r--r--program/js/app.js5
-rw-r--r--program/js/common.js17
6 files changed, 43 insertions, 10 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 226fa8a5d..4aefb3f86 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -1038,7 +1038,7 @@ function format_date($date, $format=NULL)
if (empty($ts))
return '';
- // get user's timezone
+ // get user's timezone offset
$tz = $RCMAIL->config->get_timezone();
// convert time to user's timezone
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index edda07ca7..6da5f2140 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -897,6 +897,8 @@ class rcmail
if (isset($_REQUEST['_timezone']) && $_REQUEST['_timezone'] != '_default_')
$_SESSION['timezone'] = floatval($_REQUEST['_timezone']);
+ if (isset($_REQUEST['_dstactive']) && $_REQUEST['_dstactive'] != '_default_')
+ $_SESSION['dst_active'] = intval($_REQUEST['_dstactive']);
// force reloading complete list of subscribed mailboxes
$this->imap->clear_cache('mailboxes', true);
diff --git a/program/include/rcube_config.php b/program/include/rcube_config.php
index 31b7ed6b7..4e402354d 100644
--- a/program/include/rcube_config.php
+++ b/program/include/rcube_config.php
@@ -90,6 +90,13 @@ class rcube_config
// enable display_errors in 'show' level, but not for ajax requests
ini_set('display_errors', intval(empty($_REQUEST['_remote']) && ($this->prop['debug_level'] & 4)));
+
+ // set timezone auto settings values
+ if ($this->prop['timezone'] == 'auto') {
+ $this->prop['_timezone_auto'] = true;
+ $this->prop['dst_active'] = intval(date('I'));
+ $this->prop['timezone'] = date('Z') / 3600 - $this->prop['dst_active'];
+ }
// export config data
$GLOBALS['CONFIG'] = &$this->prop;
@@ -207,6 +214,12 @@ class rcube_config
$this->userprefs = $prefs;
$this->prop = array_merge($this->prop, $prefs);
+
+ // override timezone settings with client values
+ if ($this->prop['_timezone_auto']) {
+ $this->prop['timezone'] = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : $this->prop['timezone'];
+ $this->prop['dst_active'] = isset($_SESSION['dst_active']) ? $_SESSION['dst_active'] : $this->prop['dst_active'];
+ }
}
@@ -221,17 +234,13 @@ class rcube_config
}
/**
- * Special getter for user's timezone
+ * Special getter for user's timezone offset including DST
+ *
+ * @return float Timezone offset (in hours)
*/
public function get_timezone()
{
- $tz = $this->get('timezone');
- if ($tz == 'auto')
- $tz = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : date('Z') / 3600;
- else
- $tz = intval($tz) + intval($this->get('dst_active'));
-
- return $tz;
+ return floatval($this->get('timezone')) + intval($this->get('dst_active'));
}
/**
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 9a7bee77e..043fcc64d 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -1105,6 +1105,7 @@ class rcube_template extends rcube_html_page
$input_task = new html_hiddenfield(array('name' => '_task', 'value' => 'login'));
$input_action = new html_hiddenfield(array('name' => '_action', 'value' => 'login'));
$input_tzone = new html_hiddenfield(array('name' => '_timezone', 'id' => 'rcmlogintz', 'value' => '_default_'));
+ $input_dst = new html_hiddenfield(array('name' => '_dstactive', 'id' => 'rcmlogindst', 'value' => '_default_'));
$input_url = new html_hiddenfield(array('name' => '_url', 'id' => 'rcmloginurl', 'value' => $url));
$input_user = new html_inputfield(array('name' => '_user', 'id' => 'rcmloginuser')
+ $attrib + $user_attrib);
@@ -1156,6 +1157,7 @@ class rcube_template extends rcube_html_page
$out = $input_task->show();
$out .= $input_action->show();
$out .= $input_tzone->show();
+ $out .= $input_dst->show();
$out .= $input_url->show();
$out .= $table->show();
diff --git a/program/js/app.js b/program/js/app.js
index 22599ebf0..1a8d96793 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -380,7 +380,10 @@ function rcube_webmail()
$('#rcmloginpwd').focus();
// detect client timezone
- $('#rcmlogintz').val(new Date().getTimezoneOffset() / -60);
+ var tz = new Date().getTimezoneOffset() / -60;
+ var stdtz = new Date().getStdTimezoneOffset() / -60;
+ $('#rcmlogintz').val(stdtz);
+ $('#rcmlogindst').val(tz > stdtz ? 0 : 0);
// display 'loading' message on form submit, lock submit button
$('form').submit(function () {
diff --git a/program/js/common.js b/program/js/common.js
index f69125bcc..831e44a21 100644
--- a/program/js/common.js
+++ b/program/js/common.js
@@ -671,6 +671,23 @@ RegExp.escape = function(str)
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
};
+// Extend Date prototype to detect Standard timezone without DST
+// from http://www.michaelapproved.com/articles/timezone-detect-and-ignore-daylight-saving-time-dst/
+Date.prototype.getStdTimezoneOffset = function()
+{
+ var m = 12,
+ d = new Date(null, m, 1),
+ tzo = d.getTimezoneOffset();
+
+ while (--m) {
+ d.setUTCMonth(m);
+ if (tzo != d.getTimezoneOffset()) {
+ return Math.max(tzo, d.getTimezoneOffset());
+ }
+ }
+
+ return tzo;
+}
// Make getElementById() case-sensitive on IE
if (bw.ie)