try to adjust times to the clients timezone

This commit is contained in:
Robin Appelman 2011-06-05 15:13:03 +02:00
parent bc0790381e
commit d65f8bba73
4 changed files with 28 additions and 2 deletions

4
files/ajax/timezone.php Normal file
View File

@ -0,0 +1,4 @@
<?php
session_start();
$_SESSION['timezone'] = $_GET['time'];
?>

View File

@ -37,6 +37,9 @@ OC_UTIL::addStyle( "files", "files" );
OC_UTIL::addScript( "files", "files" );
OC_UTIL::addScript( 'files', 'filelist' );
OC_UTIL::addScript( 'files', 'fileactions' );
if(!isset($_SESSION['timezone'])){
OC_UTIL::addScript( 'files', 'timezone' );
}
OC_APP::setActiveNavigationEntry( "files_index" );
// Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';

12
files/js/timezone.js Normal file
View File

@ -0,0 +1,12 @@
//send the clients time zone to the server
$(document).ready(function() {
var visitortimezone = (-new Date().getTimezoneOffset()/60);
$.ajax({
type: "GET",
url: "ajax/timezone.php",
data: 'time='+ visitortimezone,
success: function(){
location.reload();
}
});
});

View File

@ -231,8 +231,15 @@ class OC_UTIL {
* @param bool dateOnly option to ommit time from the result
*/
public static function formatDate( $timestamp,$dateOnly=false){
$timeformat=$dateOnly?'F j, Y':'F j, Y, H:i';
return date($timeformat,$timestamp);
if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it
$systemTimeZone = intval(exec('date +%z'));
$systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100);
$clientTimeZone=$_SESSION['timezone']*60;
$offset=$clientTimeZone-$systemTimeZone;
$timestamp=$timestamp+$offset*60;
}
$timeformat=$dateOnly?'F j, Y':'F j, Y, H:i';
return date($timeformat,$timestamp);
}
/**