pari: branch aadk r671 - /branches/aadk/config/setup/2.html

asterisk-gui-commits at lists.digium.com asterisk-gui-commits at lists.digium.com
Mon Apr 16 11:02:20 MST 2007


Author: pari
Date: Mon Apr 16 13:02:19 2007
New Revision: 671

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=671
Log:
Time will be displayed in LocalTime of the browser - but will be set on the appliance in UTC

Modified:
    branches/aadk/config/setup/2.html

Modified: branches/aadk/config/setup/2.html
URL: http://svn.digium.com/view/asterisk-gui/branches/aadk/config/setup/2.html?view=diff&rev=671&r1=670&r2=671
==============================================================================
--- branches/aadk/config/setup/2.html (original)
+++ branches/aadk/config/setup/2.html Mon Apr 16 13:02:19 2007
@@ -98,72 +98,62 @@
 
 
 function sysinfocallbacks_loaded(){
-	var temp = today.split(" ");
-	if(temp[2] == ""){ temp.splice(2,1) ; }
-	var dayofweek = temp[0]; // Fri
-	var monthofyear = temp[1]; // Dec
-	var dayofmonth = temp[2]; // 8
-	var timeofday = temp[3]; // 23:59:59
-	var timezone = temp[4]; // CST
-	var year = temp[5]; // 2006
-
-	for(var i=0; i < $('moy').length; i++){
-		if ( $('moy').options[i].value.toLowerCase() == monthofyear.toLowerCase() ){
-			$('moy').selectedIndex = i;
+	var tmp = today.split(" ");
+	if(tmp[2] == ""){ tmp.splice(2,1) ; }
+	// tmp[0]; // Fri
+	// tmp[1]; // Dec
+	// tmp[2]; // 8
+	// tmp[3]; // 23:59:59
+	// tmp[4]; // We assume this is always UTC 
+	// tmp[5]; // 2006
+	var temp = tmp[3].split(':'); // hours =  parseInt(temp[0]), minutes = parseFloat(temp[1]);
+	// convert these values to local time
+	var months_strings = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug","sep","oct","nov","dec"];
+	for(var i=0; i < months_strings.length; i++){
+		if ( months_strings[i] == tmp[1].toLowerCase() ){
 			break;
 		}
 	}
 
-	for(var i=0; i < $('dom').length; i++){
-		if ( $('dom').options[i].value == parseFloat(dayofmonth) ){
-			$('dom').selectedIndex = i;
-			break;
-		}
-	}
-
-	var temp = timeofday.split(':');
-
-	var hourofday = parseInt(temp[0]);
-	if(hourofday <=12 ){
-		if(hourofday == 0){
+	var utc_date = new Date();
+	utc_date.setUTCFullYear ( tmp[5] , i , tmp[2] );
+	utc_date.setUTCHours ( parseInt(temp[0]), parseInt(temp[1]) );
+
+	var lt_hours = utc_date.getHours(); // 0 to 23
+	var lt_minutes = utc_date.getMinutes(); // 0 to 59
+	var lt_month = utc_date.getMonth(); // 0 to 11
+	var lt_dom = utc_date.getDate(); // 1 to 31
+	var lt_year = utc_date.getFullYear() ; // 2007
+
+	$('moy').selectedIndex = Number(lt_month) ;
+	$('dom').selectedIndex = Number(lt_dom) -1 ;
+
+	if(lt_hours <=12 ){
+		if(lt_hours == 0){
 			$('hod').selectedIndex = 11;
 			$('ampm').selectedIndex = 0;
-		}else if(hourofday == 12){
+		}else if(lt_hours == 12){
 			$('hod').selectedIndex = 11;
 			$('ampm').selectedIndex = 1;
 		}else{
-			for(var i=0; i < $('hod').length; i++){
-				if (  $('hod').options[i].value ==  hourofday ){
-					$('hod').selectedIndex = i;
-					break;
-				}
-			}
+			$('hod').selectedIndex = Number(lt_hours) -1;
 			$('ampm').selectedIndex = 0;
 		}
 	}else{
-		var hourofday = parseInt(temp[0]) -12 ;
+		var lt_hours = lt_hours -12 ;
 		$('ampm').selectedIndex = 1;
-		for(var i=0; i < $('hod').length; i++){
-			if (  $('hod').options[i].value ==  hourofday ){
-				$('hod').selectedIndex = i;
-				break;
-			}
-		}
+		$('hod').selectedIndex = Number(lt_hours) -1;
 	}
 	
-	for(var i=0; i < $('minute').length; i++){
-		if (  $('minute').options[i].value == parseFloat(temp[1])  ){
-			$('minute').selectedIndex = i;
-			break;
-		}
-	}
+	$('minute').selectedIndex = Number(lt_minutes);
 
 	for(var i=0; i < $('year').length; i++){
-		if (  $('year').options[i].value == parseFloat(year)  ){
+		if (  $('year').options[i].value == String(lt_year)  ){
 			$('year').selectedIndex = i;
 			break;
 		}
 	}
+
 	parent.$('next').disabled = false;
 	parent.$('next').onclick = function(){	 
 		if(changed){
@@ -185,16 +175,41 @@
 		}
 	};
 
+	// convert local time to UTC
+	var lt_minutes = $('minute').value ; // 0 to 59
+	var lt_month = $('moy').selectedIndex ; // 0 to 11
+	var lt_dom = $('dom').value ; // 1 to 31
+	var lt_year = $('year').value ; // 2007
+
 	// prepare commands to set the date 
 	if( $('ampm').value == "AM"  ){
-		var hourofday = ($('hod').value == "12" )? "00":$('hod').value;
+		var lt_hours = ($('hod').value == "12" )? "00":$('hod').value;
 	}else if( $('ampm').value == "PM"){
-		var hourofday = ($('hod').value == "12") ?parseInt( $('hod').value) : parseInt($('hod').value) + 12 ;
-	}
-
-	var tmp_month = $('moy').selectedIndex +1 ;
-	if (tmp_month < 10) { tmp_month = "0"+ tmp_month ; } 
-	var newdate =  tmp_month + $('dom').value + hourofday + $('minute').value + $('year').value  ;
+		var lt_hours = ($('hod').value == "12") ? parseInt($('hod').value) : parseInt($('hod').value) + 12 ;
+	}
+
+	var lt = new Date();
+	lt.setFullYear ( lt_year, lt_month, lt_dom );
+	lt.setHours ( lt_hours, lt_minutes );
+
+	var utc_hours = lt.getUTCHours(); // 0 to 23
+	var utc_minutes = lt.getUTCMinutes(); // 0 to 59
+	var utc_month = lt.getUTCMonth(); // 0 to 11
+	var utc_dom = lt.getUTCDate(); // 1 to 31
+	var utc_year = lt.getUTCFullYear() ; // 2007
+
+	//console.log(" utc_hours :: " + utc_hours );
+	//console.log(" utc_minutes :: " + utc_minutes );
+	//console.log(" utc_month :: " + utc_month );
+	//console.log(" utc_dom :: " + utc_dom );
+	//console.log(" utc_year :: " + utc_year );
+
+	if (utc_month < 10) { utc_month = "0"+ String(utc_month+1) ; }
+ 	if (utc_dom < 10) { utc_dom = "0"+ String(utc_dom) ; }
+ 	if (utc_hours < 10) { utc_hours = "0"+ String(utc_hours) ; }
+ 	if (utc_minutes < 10) { utc_minutes = "0"+ String(utc_minutes) ; }
+	var newdate =  utc_month + utc_dom + utc_hours + utc_minutes + utc_year ;
+
 	opt.parameters="action=originate&channel=" + encodeURIComponent("Local/executecommand@"+parent.asterisk_guitools ) + "&Variable=command%3d"+ encodeURIComponent("date -s " + newdate ) + "&application=noop&timeout=60000";
 	
 	var tmp = new Ajax.Request(rawman_url, opt);



More information about the asterisk-gui-commits mailing list