add comments for stardate and revise it by 30min to be more accurate
[tricorder.git] / js / tricorder.js
index f88ebb120e470277fc7818a1d35a095e2ff76a5e..2574b01f6fb7e334618e130079fa19b991ddb7bc 100644 (file)
@@ -32,13 +32,20 @@ window.onload = function() {
 }
 
 function updateStardate() {
+  // Stardate rules foggy at best. See http://en.wikipedia.org/wiki/Stardate
+  // and the Memory Alpha article linked there for more details.
+  // We roughly lean on TNG scale by splitting an Earth year into exactly 1000
+  // units, but we put the 0 point at the TV premiere of The Original Series.
   if (!gStardate)
     gStardate = document.getElementById("stardate");
 
   var curDate = new Date();
 
   if (!gSDBase)
-    gSDBase = new Date("September 8, 1966 20:00:00 EST");
+    // Star Trek premiered on Thursday, September 8, 1966, at 7:30PM or 8:30PM
+    // depending on time zone in the United States.
+    // See http://www.startrek.com/article/star-trek-and-newspapers-part-2
+    gSDBase = new Date("September 8, 1966 19:30:00 EST");
 
   var sdateval = (curDate - gSDBase) / (86400 * 365.2425);
   gStardate.textContent = sdateval.toFixed(1);
@@ -226,10 +233,28 @@ var gModDev = {
     gSounds.scan.pause();
   },
   updateBattery: function() {
-    document.getElementById("devBattLevel").textContent = (navigator.battery.level * 100).toFixed(1) + "%";
-    document.getElementById("devBattStatus").textContent = 
-        navigator.battery.charging ? "charging, " + navigator.battery.chargingTime + "s remaining"
-                                   : navigator.battery.dischargingTime + "s usage remaining";
+    document.getElementById("devBattLevel").textContent =
+        (navigator.battery.level * 100).toFixed(1) + "%";
+    if (navigator.battery.charging) {
+      if (navigator.battery.chargingTime == 0 ||
+          navigator.battery.chargingTime == Infinity) {
+        document.getElementById("devBattStatus").textContent = "charging";
+      }
+      else {
+        document.getElementById("devBattStatus").textContent = 
+            "charging, " + navigator.battery.chargingTime + "s remaining";
+      }
+    }
+    else {
+      if (navigator.battery.dischargingTime == 0 ||
+          navigator.battery.dischargingTime == Infinity) {
+        document.getElementById("devBattStatus").textContent = "discharging";
+      }
+      else {
+        document.getElementById("devBattStatus").textContent = 
+            navigator.battery.dischargingTime + "s usage remaining";
+      }
+    }
   },
   batteryTimer: null,
 }