From 91937d5b312a37d2b602623f57dad3c0ae8af813 Mon Sep 17 00:00:00 2001
From: Fatih Acet <acetfatih@gmail.com>
Date: Fri, 3 Jun 2016 00:00:48 +0300
Subject: [PATCH] Added a new common util called $.timefor.

It will use $.timeago behind the scene and it does the opposite of what $.timeago does.

$.timefor("Thu Jun 05 2016 23:40:39 GMT+0300 (EEST)") will return "3 days remaining".
---
 .../javascripts/lib/common_utils.js.coffee    | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 app/assets/javascripts/lib/common_utils.js.coffee

diff --git a/app/assets/javascripts/lib/common_utils.js.coffee b/app/assets/javascripts/lib/common_utils.js.coffee
new file mode 100644
index 00000000000..a7cc07608ab
--- /dev/null
+++ b/app/assets/javascripts/lib/common_utils.js.coffee
@@ -0,0 +1,24 @@
+((w) ->
+
+  jQuery.timefor = (time, suffix, expiredLabel) ->
+
+    return '' unless time
+
+    suffix       or= 'remaining'
+    expiredLabel or= 'expired'
+
+    jQuery.timeago.settings.allowFuture = yes
+
+    { suffixFromNow } = jQuery.timeago.settings.strings
+    jQuery.timeago.settings.strings.suffixFromNow = suffix
+
+    timefor = $.timeago time
+
+    if timefor.indexOf('ago') > -1
+      timefor = expiredLabel
+
+    jQuery.timeago.settings.strings.suffixFromNow = suffixFromNow
+
+    return timefor
+
+) window
-- 
GitLab