]> WPIA git - gigi.git/blobdiff - static/static/localDate.js
Suggestion to display datetimes in local format
[gigi.git] / static / static / localDate.js
diff --git a/static/static/localDate.js b/static/static/localDate.js
new file mode 100644 (file)
index 0000000..0935810
--- /dev/null
@@ -0,0 +1,29 @@
+(function() {
+       function init(){
+               var elems = document.getElementsByTagName("time");
+               for(var i = 0; i < elems.length; i++){
+                       elems[i].setAttribute("title", elems[i].textContent);
+                       elems[i].removeChild(elems[i].firstChild);
+                       var t = elems[i].getAttribute("datetime");
+                       elems[i].appendChild(document.createTextNode(new Date(t).toLocaleString(undefined, {timeZoneName: "short",
+                               year: "numeric",
+                               month: "2-digit",
+                               day: "2-digit",
+                               hour: "2-digit",
+                               minute: "2-digit",
+                               second: "2-digit"})
+                               ));
+               }
+       }
+       (function(oldLoad) {
+               if (oldLoad == undefined) {
+                       window.onload = init;
+               } else {
+                       window.onload = function() {
+                               init();
+                               oldLoad();
+                       }
+               }
+       })(window.onload);
+
+})();