
darjeelingApp.filter('removeSpam', function () {
    return function (string) {
        var thingsToRemove = [];
        var doc = document.implementation.createHTMLDocument("");
        doc.documentElement.innerHTML = string;

        var qcRss = doc.getElementsByTagName("map");
        for (var i = 0; i < qcRss.length; i++) {
            var node = qcRss[i];
            if (node.name.startsWith("admap")) {
                thingsToRemove = thingsToRemove.concat(node.parentNode);
                if (node.parentNode.nextSibling.tagName == "TABLE") {
                    thingsToRemove = thingsToRemove.concat(node.parentNode.nextSibling);
                }
            }
        }

        thingsToRemove = thingsToRemove.concat([].slice.call(doc.getElementsByClassName('feedflare')));

        for (var i = 0; i < thingsToRemove.length; i++) {
            thingsToRemove[i].parentNode.removeChild(thingsToRemove[i]);
        }

        return doc.documentElement.innerHTML;
    };
});

darjeelingApp.filter('trust', function ($sce) {
    return function (raw) {
        return $sce.trustAsHtml(raw);
    };
});

darjeelingApp.filter('prettyDate', function () {
    var msPerMinute = 1000 * 60;
    var msPerHour = 1000 * 60 * 60;
    var msPerDay = 1000 * 60 * 60 * 24;

    function pluralize(qty, label) {
        return qty + label.replace("(s)", qty > 1 ? "s" : "");
    }

    return function (rawDate) {
        var date = new Date(rawDate);
        var dateDiff = new Date() - date;

        if (dateDiff / msPerMinute < 60) {
            return pluralize(Math.floor(dateDiff / msPerMinute), " minute(s) ago");
        } else if (dateDiff / msPerHour < 24) {
            return pluralize(Math.floor(dateDiff / msPerHour), " hour(s) ago");
        } else if (dateDiff / msPerDay < 4) {
            return pluralize(Math.floor(dateDiff / msPerDay), " day(s) ago");
        }

        return date.toDateString();
    };
});

darjeelingApp.filter('fullDate', function () {
    return function (rawDate) {
        return new Date(rawDate).toString();
    }
});

@@ -1284,25 +1284,22 @@
 unction 
-pluralize
+format
 (qty, la
@@ -1313,24 +1313,19 @@
     
-    return qty +
+%09var unit =
  lab
@@ -1342,19 +1342,29 @@
 (%22(s)%22, 
+Math.abs(
 qty
+)
  %3E 1 ? %22
@@ -1369,24 +1369,105 @@
  %22s%22 : %22%22);%0A
+    %09%0A        return qty%3C0 ? %22in %22 + Math.abs(qty) + unit : qty + unit + %22 ago%22;%0A
     %7D%0A%0A    r
@@ -1581,24 +1581,33 @@
 %0A        if 
+(Math.abs
 (dateDiff / 
@@ -1617,16 +1617,17 @@
 erMinute
+)
  %3C 60) %7B
@@ -1642,33 +1642,30 @@
      return 
-pluralize
+format
 (Math.floor(
@@ -1700,20 +1700,16 @@
 inute(s)
- ago
 %22);%0A    
@@ -1714,32 +1714,41 @@
       %7D else if 
+(Math.abs
 (dateDiff / msPe
@@ -1752,16 +1752,17 @@
 sPerHour
+)
  %3C 24) %7B
@@ -1777,33 +1777,30 @@
      return 
-pluralize
+format
 (Math.floor(
@@ -1831,20 +1831,16 @@
  hour(s)
- ago
 %22);%0A    
@@ -1853,16 +1853,25 @@
 else if 
+(Math.abs
 (dateDif
@@ -1882,16 +1882,17 @@
 msPerDay
+)
  %3C 4) %7B%0A
@@ -1914,17 +1914,14 @@
 urn 
-pluralize
+format
 (Mat
@@ -1958,20 +1958,16 @@
 %22 day(s)
- ago
 %22);%0A    

Fix #10: Handle future dates