Explorar el Código

Fixed time zone bug

Fixed bug that was falsely alerting data was old when the data was current. This had to do with accounting for different user time zones.
Josh Smith hace 5 años
padre
commit
6f62a2adf7
Se han modificado 1 ficheros con 12 adiciones y 3 borrados
  1. 12 3
      js/checkdiff.js

+ 12 - 3
js/checkdiff.js

@@ -4,15 +4,24 @@
  */
 
 function checkDiff(datestr) {
-    var date = new Date();
+    var newdate = new Date();
     var refreshed = new Date(datestr);
+    var dtz = date.geTtimezoneOffset()/60;
+    var sdtz = refreshed.getTimezoneOffset()/60;
+
+    if (dtz == sdtz ) {
+    	var date = newdate;
+    } else {
+	var date = new Date(newdate.getTime() + sdtz);
+    }
+
     var diff = 30 * 60 * 1000; /* 30 min diff is OK without a warning*/
     var text = document.createElement('div');
+
     // Fixme: Add "icon"
     if (date - refreshed > diff) {
         text.innerHTML = "<i class='fa fa-exclamation-triangle m-orange'></i><b> Old Weather Data </b>";
-//  } else {
-//    text.innerHTML = "<i class=''></i> Fresh Weather";
     }
+
     document.getElementById('freshweather').appendChild(text);
 }