[projects/pld-builder.new] format requests with relative date

glen glen at pld-linux.org
Wed Jan 20 17:23:21 CET 2016


commit d867e693355d9edfbbf7381e8bcee24dbd7b620c
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Wed Jan 20 18:22:13 2016 +0200

    format requests with relative date
    
    seems the current implementation showing in users' timezone was broken
    anyway when DST is not active

 PLD_Builder/bqueue.py  |  1 +
 PLD_Builder/request.py | 14 ++++++++++++--
 PLD_Builder/script.js  | 13 ++-----------
 3 files changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/PLD_Builder/bqueue.py b/PLD_Builder/bqueue.py
index c324f81..30ecf20 100644
--- a/PLD_Builder/bqueue.py
+++ b/PLD_Builder/bqueue.py
@@ -44,6 +44,7 @@ class B_Queue:
         <title>PLD builder queue</title>
         <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="style.css">
         <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
+        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.min.js"></script>
         <script type="text/javascript" src="script.js"></script>
     </head>
 <body>
diff --git a/PLD_Builder/request.py b/PLD_Builder/request.py
index 588a9c4..9cdc055 100644
--- a/PLD_Builder/request.py
+++ b/PLD_Builder/request.py
@@ -1,6 +1,7 @@
 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
 
 from xml.dom.minidom import *
+from datetime import datetime
 import string
 import time
 import xml.sax.saxutils
@@ -8,6 +9,7 @@ import fnmatch
 import os
 import urllib
 import cgi
+import pytz
 
 import util
 import log
@@ -39,7 +41,6 @@ def escape(s):
 # so we could parse it in javascript
 def tzdate(t):
     # as strftime %z is unofficial, and does not work, need to make it numeric ourselves
-#    date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t))
     date = time.strftime("%a %b %d %Y %H:%M:%S", time.localtime(t))
     # NOTE: the altzone is showing CURRENT timezone, not what the "t" reflects
     # NOTE: when DST is off timezone gets it right, altzone not
@@ -50,6 +51,12 @@ def tzdate(t):
     tz = '%+05d' % (-tzoffset / 3600 * 100)
     return date + ' ' + tz
 
+# return date in iso8601 format
+def iso8601(ts, timezone='UTC'):
+    tz = pytz.timezone(timezone)
+    dt = datetime.fromtimestamp(ts, tz)
+    return dt.isoformat()
+
 def is_blank(e):
     return e.nodeType == Element.TEXT_NODE and string.strip(e.nodeValue) == ""
 
@@ -111,12 +118,15 @@ class Group:
     def dump_html(self, f):
         f.write(
             "<div id=\"%(no)d\" class=\"request %(flags)s\">\n"
-            "<a href=\"#%(no)d\">%(no)d</a>. <span id=\"tz\">%(time)s</span> from <b class=requester>%(requester)s</b> "
+            "<a href=\"#%(no)d\">%(no)d</a>. "
+            "<time class=\"timeago\" datetime=\"%(datetime)s\">%(time)s</time> "
+            "from <b class=requester>%(requester)s</b> "
             "<small>%(id)s, prio=%(priority)d, jobs=%(max_jobs)d, %(flags)s</small>\n"
         % {
             'no': self.no,
             'id': '<a href="srpms/%(id)s">%(id)s</a>' % {'id': self.id},
             'time': escape(tzdate(self.time)),
+            'datetime': escape(iso8601(self.time)),
             'requester': escape(self.requester),
             'priority': self.priority,
             'max_jobs': self.max_jobs,
diff --git a/PLD_Builder/script.js b/PLD_Builder/script.js
index 6019aeb..5b8b060 100644
--- a/PLD_Builder/script.js
+++ b/PLD_Builder/script.js
@@ -2,18 +2,9 @@ jQuery(function($) {
 	update_tz();
 	filter_requesters();
 
-	// update date stamps to reflect viewers timezone
+	// setup relative time display
 	function update_tz() {
-		$('span#tz').each(function(i, el) {
-			var $el = $(el);
-			dt = new Date($el.text()).toString();
-			// strip timezone name, it is usually wrong when not initialized
-			// from TZ env, but reverse calculated from os data
-			dt = dt.replace(/\s+\(.+\)/, "");
-			// strip "GMT"
-			dt = dt.replace(/GMT/, "");
-			$el.text(dt);
-		});
+		$('time.timeago').timeago();
 	}
 
 	// draw filter for requesters
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/d867e693355d9edfbbf7381e8bcee24dbd7b620c



More information about the pld-cvs-commit mailing list