Sfoglia il codice sorgente

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 5 anni fa
parent
commit
6f62a2adf7
1 ha cambiato i file con 12 aggiunte e 3 eliminazioni
  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);
 }