]> WPIA git - gigi.git/commitdiff
Suggestion to display datetimes in local format
authorFelix Dörre <felix@dogcraft.de>
Fri, 17 Jun 2016 14:30:30 +0000 (16:30 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sun, 19 Jun 2016 14:22:06 +0000 (16:22 +0200)
Change-Id: I3092504a8aceef27540b3d878f0e92eb8302783d

src/org/cacert/gigi/Gigi.templ
src/org/cacert/gigi/output/template/Template.java
static/static/localDate.js [new file with mode: 0644]

index 26ce9206e4c3c73e4d7fed2fe7d569726c5f5bd1..0bb64c04cc249b448b8c029afaec1a64f122dbb5 100644 (file)
@@ -16,6 +16,7 @@
         <script src="<?=$static?>/js/jquery.min.js"></script>
         <script src="<?=$static?>/js/bootstrap.min.js"></script>
         <script src="<?=$static?>/expert.js"></script>
+        <script src="<?=$static?>/localDate.js"></script>
     </head>
 <body>
 <nav class="navbar navbar-default">
index cc56baf813b8e731c855c71cf0213de912f0651c..15f3408d28ce41d10d55b4f9491fdaf223cb0d84 100644 (file)
@@ -213,9 +213,11 @@ public class Template implements Outputable {
         } else if (s instanceof DayDate) {
             out.print(DateSelector.getDateFormat().format(((DayDate) s).toDate()));
         } else if (s instanceof Date) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            out.print(sdf.format(s));
-            out.print(" UTC");
+            SimpleDateFormat sdfUI = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+            out.print("<time datetime=\"" + sdf.format(s) + "\">");
+            out.print(sdfUI.format(s));
+            out.print(" UTC</time>");
         } else {
             out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString())));
         }
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);
+
+})();