From 2cc75b6939b43162a9c60f7d12159c7a1c9a707e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 8 Jan 2011 18:41:23 -0600 Subject: Add a long datetime parser to table sorting code This comes into play on our new developer clocks page, where the last column was not sorting at all as expected. Signed-off-by: Dan McGee --- media/archweb.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/media/archweb.js b/media/archweb.js index c5025ded..1c80ab64 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -36,18 +36,34 @@ if(typeof $.tablesorter !== "undefined") { $.tablesorter.addParser({ /* sorts duration; put '', 'unknown', and '∞' last. */ id: 'duration', - is: function(s,table) { + re: /^([0-9]+):([0-5][0-9])$/, + is: function(s) { var special = ['', 'unknown', '∞']; - return ($.inArray(s, special) > -1) || /^[0-9]+:[0-5][0-9]$/.test(s); + return ($.inArray(s, special) > -1) || this.re.test(s); }, format: function(s) { var special = ['', 'unknown', '∞']; if($.inArray(s, special) > -1) return Number.MAX_VALUE; - matches = /^([0-9]+):([0-5][0-9])$/.exec(s); + var matches = this.re.exec(s); return matches[1] * 60 + matches[2]; }, type: 'numeric' }); + $.tablesorter.addParser({ + id: 'longDateTime', + re: /^(\d{4})-(\d{2})-(\d{2}) ([012]\d):([0-5]\d)(:([0-5]\d))?( (\w+))?$/, + is: function (s) { + return this.re.test(s); + }, + format: function (s) { + var matches = this.re.exec(s); + /* skip group 6, group 7 is optional seconds */ + if(matches[7] == undefined) matches[7] = "0"; + return $.tablesorter.formatFloat(new Date( + matches[1],matches[2],matches[3],matches[4],matches[5],matches[7]).getTime()); + }, + type: "numeric" + }); } /* news/add.html */ -- cgit v1.2.3-2-g168b