From d4f6d65e1d3406453e43f289cdba3d06c7d64fe0 Mon Sep 17 00:00:00 2001
From: Kegan Dougal <kegan@matrix.org>
Date: Fri, 14 Nov 2014 15:34:19 +0000
Subject: [PATCH] Add extra checks to duration filter.

---
 syweb/webclient/app-filter.js             | 3 +++
 syweb/webclient/test/unit/filters.spec.js | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/syweb/webclient/app-filter.js b/syweb/webclient/app-filter.js
index b0971e8493..003e6d3f11 100644
--- a/syweb/webclient/app-filter.js
+++ b/syweb/webclient/app-filter.js
@@ -26,6 +26,9 @@ angular.module('matrixWebClient')
         var h = parseInt(t / (60 * 60)) % 24;
         var d = parseInt(t / (60 * 60 * 24));
         if (t < 60) {
+            if (t < 0) {
+                return "0s";
+            }
             return s + "s";
         }
         if (t < 60 * 60) {
diff --git a/syweb/webclient/test/unit/filters.spec.js b/syweb/webclient/test/unit/filters.spec.js
index e8944cbfc2..fe31da709b 100644
--- a/syweb/webclient/test/unit/filters.spec.js
+++ b/syweb/webclient/test/unit/filters.spec.js
@@ -285,6 +285,11 @@ describe('duration filter', function() {
         var output = durationFilter(1000*60*60*2 + 1000*60*35);
         expect(output).toEqual("2h");
     });
+    
+    it("should represent -ve numbers as '0s'", function() {
+        var output = durationFilter(-2000);
+        expect(output).toEqual("0s");
+    });
 });
 
 describe('orderMembersList filter', function() {
-- 
GitLab