diff options
author | Fatih Acet <acetfatih@gmail.com> | 2016-06-03 00:00:48 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-06-03 00:00:48 +0300 |
commit | 91937d5b312a37d2b602623f57dad3c0ae8af813 (patch) | |
tree | 734a64b877319cbf856fc391c6132158f6d8f5ba /app/assets/javascripts/lib | |
parent | 94b0da42302959ea642c4dc3037db0d4f195eb55 (diff) | |
download | gitlab-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".
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r-- | app/assets/javascripts/lib/common_utils.js.coffee | 24 |
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 |