Browse Source

- Final (?) fix to the timezone select box in admin section

pull/16/head
Christine Ho 11 years ago
parent
commit
d85d56d868
  1. 10
      app/helpers/TimezoneHelper.php
  2. 9
      app/widgets/AdminMain/AdminMain.php
  3. 57
      app/widgets/AdminMain/admin.js
  4. 2
      app/widgets/AdminMain/adminmain.tpl

10
app/helpers/TimezoneHelper.php

@ -41,17 +41,15 @@
$pretty_offset = "UTC${offset_prefix}${offset_formatted}";
$t = new DateTimeZone($timezone);
$c = new DateTime(null, $t);
$current_time = $c->format('G:i');
$split = explode("/", $timezone);
$timezone_list[$timezone] = "$split[1] ($split[0]) - $current_time (${pretty_offset})";
$timezone_list[$timezone] = "$split[1]/$split[0] (${pretty_offset})";
}
asort($timezone_list);
return $timezone_list;
}
/*
* Get the user local timezone

9
app/widgets/AdminMain/AdminMain.php

@ -47,11 +47,12 @@ class AdminMain extends WidgetBase
return requestURL($url, 1);
}
public function date()
public function date($timezone)
{
//return date('l jS \of F Y h:i:s A');
#return date('F j, Y G:i:s');
return prepareDate(time());
$t = new DateTimeZone($timezone);
$c = new DateTime(null, $t);
$current_time = $c->format('D M j Y G:i:s');
return $current_time;
}
function display()

57
app/widgets/AdminMain/admin.js

@ -1,42 +1,43 @@
var tz_list;
var original = true;
var operators = {
'+': function(a, b) { return a + b },
'-': function(a, b) { return a - b },
};
function update(init, elt){
original = false;
function update(elt){
if (elt.selectedIndex == -1)
return null;
//Get the offset from the selected option
text = elt.options[elt.selectedIndex].text;
h_m = text.split("(")[1].split(")")[0].split(".");
var today = init;
if(h_m[0]<0){
h_m[0] = h_m[0].substr(1);
today.setHours(today.getHours() - parseInt(h_m[0]));
today.setMinutes(today.getMinutes() - parseInt(h_m[1]));
}
else{
today.setHours(today.getHours() + parseInt(h_m[0]));
today.setMinutes(today.getMinutes() + parseInt(h_m[1]));
}
return today;
//Determine if it is a positive or negative offset
sign = text.indexOf("+") > -1 ? "+" : "-";
//Seperate hours and minutes and get the offset in ms
h_m = text.split(sign)[1].split(")")[0].split(":");
tzOffset = parseInt(h_m[0]) * 3600000 + parseInt(h_m[1]) * 60000;
//Get the offset between your computer and UTC
pcOffset = new Date().getTimezoneOffset() * 60000;
return new Date(operators[sign]((new Date().getTime() + pcOffset), tzOffset));
}
movim_add_onload(function()
{
tz_list = document.querySelector("#timezone");
var d = new Date(document.querySelector(".dTimezone").innerHTML);
tz_list.onchange = function(e){
//document.querySelector(".dTimezone").innerHTML = update(d, tz_list).toUTCString();
newTime = update(tz_list);
formatDate(newTime);
}
setInterval(
function(){ //increment time each second
date = new Date(document.querySelector(".dTimezone").innerHTML).getTime() + 1000;
date = formatDate(new Date(date));
}
/*setInterval(
function(){
/*if(original){
//date = new Date();
document.querySelector(".dTimezone").innerHTML = date.toUTCString();
}
else{/*
date = new Date(document.querySelector(".dTimezone").innerHTML);
date.setSeconds(date.getSeconds() + 1);
document.querySelector(".dTimezone").innerHTML = date.toUTCString();
//}
,1000);
formatDate = function (newTime){
h = newTime.getHours()<10 ? "0" + newTime.getHours() : newTime.getHours();
m = newTime.getMinutes()<10 ? "0" + newTime.getMinutes() : newTime.getMinutes();
s = newTime.getSeconds()<10 ? "0" + newTime.getSeconds() : newTime.getSeconds();
document.querySelector(".dTimezone").innerHTML = newTime.toDateString() + " " + h+ ":" + m + ":" + s;
}
,1000);*/
});

2
app/widgets/AdminMain/adminmain.tpl

@ -73,7 +73,7 @@
</select>
</div>
<br /><br />
<span class="dTimezone">{$c->date()}</span>
<span class="dTimezone">{$c->date($conf->timezone)}</span>
</div>
</fieldset>

Loading…
Cancel
Save