summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-06-03 00:00:48 +0300
committerFatih Acet <acetfatih@gmail.com>2016-06-03 00:00:48 +0300
commit91937d5b312a37d2b602623f57dad3c0ae8af813 (patch)
tree734a64b877319cbf856fc391c6132158f6d8f5ba
parent94b0da42302959ea642c4dc3037db0d4f195eb55 (diff)
downloadgitlab-ce-91937d5b312a37d2b602623f57dad3c0ae8af813.tar.gz
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".
-rw-r--r--app/assets/javascripts/lib/common_utils.js.coffee24
1 files changed, 24 insertions, 0 deletions
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