diff --git a/app/helpers/TimezoneHelper.php b/app/helpers/TimezoneHelper.php index a645f5720..fcdbfbe7f 100644 --- a/app/helpers/TimezoneHelper.php +++ b/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 diff --git a/app/widgets/AdminMain/AdminMain.php b/app/widgets/AdminMain/AdminMain.php index 2df4af111..149322f3d 100644 --- a/app/widgets/AdminMain/AdminMain.php +++ b/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() diff --git a/app/widgets/AdminMain/admin.js b/app/widgets/AdminMain/admin.js index ddf473064..a43870ad8 100644 --- a/app/widgets/AdminMain/admin.js +++ b/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);*/ }); diff --git a/app/widgets/AdminMain/adminmain.tpl b/app/widgets/AdminMain/adminmain.tpl index 15add75c0..378d5b18f 100644 --- a/app/widgets/AdminMain/adminmain.tpl +++ b/app/widgets/AdminMain/adminmain.tpl @@ -73,7 +73,7 @@

- {$c->date()} + {$c->date($conf->timezone)}