add automatic timezone (based on client tz offset)

This commit is contained in:
Andrew Dolgov 2013-04-26 10:31:57 +04:00
parent 5ddef5ba23
commit 6bfc97da86
5 changed files with 19 additions and 7 deletions

View File

@ -334,6 +334,7 @@ class RPC extends Handler_Protected {
$_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true";
$_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true"; $_SESSION["hasSandbox"] = $_REQUEST["hasSandbox"] === "true";
$_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true"; $_SESSION["hasMp3"] = $_REQUEST["hasMp3"] === "true";
$_SESSION["clientTzOffset"] = $_REQUEST["clientTzOffset"];
$reply = array(); $reply = array();

View File

@ -862,13 +862,18 @@
$user_tz_string = get_pref('USER_TIMEZONE', $owner_uid); $user_tz_string = get_pref('USER_TIMEZONE', $owner_uid);
try { if ($user_tz_string != 'Automatic') {
if (!$user_tz) $user_tz = new DateTimeZone($user_tz_string);
} catch (Exception $e) {
$user_tz = $utc_tz;
}
$tz_offset = $user_tz->getOffset($dt); try {
if (!$user_tz) $user_tz = new DateTimeZone($user_tz_string);
} catch (Exception $e) {
$user_tz = $utc_tz;
}
$tz_offset = $user_tz->getOffset($dt);
} else {
$tz_offset = (int) $_SESSION["clientTzOffset"];
}
$user_timestamp = $dt->format('U') + $tz_offset; $user_timestamp = $dt->format('U') + $tz_offset;

View File

@ -962,8 +962,11 @@ function init() {
dojo.addOnLoad(function() { dojo.addOnLoad(function() {
loading_set_progress(50); loading_set_progress(50);
var clientTzOffset = new Date().getTimezoneOffset() * 60;
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: {op: "rpc", method: "sanityCheck"}, parameters: {op: "rpc", method: "sanityCheck",
clientTzOffset: clientTzOffset },
onComplete: function(transport) { onComplete: function(transport) {
backend_sanity_check_callback(transport); backend_sanity_check_callback(transport);
} }); } });

View File

@ -256,10 +256,12 @@ function init() {
var hasAudio = !!a.canPlayType; var hasAudio = !!a.canPlayType;
var hasSandbox = "sandbox" in document.createElement("iframe"); var hasSandbox = "sandbox" in document.createElement("iframe");
var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, '')); var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
var clientTzOffset = new Date().getTimezoneOffset() * 60;
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio, parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
hasMp3: hasMp3, hasMp3: hasMp3,
clientTzOffset: clientTzOffset,
hasSandbox: hasSandbox}, hasSandbox: hasSandbox},
onComplete: function(transport) { onComplete: function(transport) {
backend_sanity_check_callback(transport); backend_sanity_check_callback(transport);

View File

@ -1,3 +1,4 @@
Automatic
Africa/Abidjan Africa/Abidjan
Africa/Accra Africa/Accra
Africa/Addis_Ababa Africa/Addis_Ababa