Explorar o 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 %!s(int64=5) %!d(string=hai) anos
pai
achega
6f62a2adf7
Modificáronse 1 ficheiros con 12 adicións e 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);
 }