From a99109ec80b338086eb597a34b1cf4e80d1a48d4 Mon Sep 17 00:00:00 2001 From: jomo Date: Sun, 4 May 2014 04:17:30 +0200 Subject: [PATCH] use long words for time --- app/assets/javascripts/ago.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/ago.js b/app/assets/javascripts/ago.js index 1cdeb8d..0b337b9 100644 --- a/app/assets/javascripts/ago.js +++ b/app/assets/javascripts/ago.js @@ -1,10 +1,10 @@ $.fn.ago = function(callback) { units = [ - ['m', 60], - ['h', 3600], - ['d', 86400], - ['w', 604800], - ['y', 31536000] + ['minute', 60], + ['hour', 3600], + ['day', 86400], + ['week', 604800], + ['year', 31536000] ]; this.each(function() { ago_date = callback ? callback(this) : new Date($(this).text()); @@ -20,8 +20,13 @@ $.fn.ago = function(callback) { }); if (ago_unit !== null) { - unit = units[ago_unit]; - ago_str = Math.abs(Math.floor(ago_time/unit[1])).toString() + unit[0] + (ago_time < 0 ? " ahead" : " ago"); + unit = units[ago_unit]; + ago_time = Math.abs(Math.floor(ago_time/unit[1])) + ago_str = ago_time.toString() + " " + unit[0] + if (ago_time != 1) { + ago_str += "s"; + } + ago_str += (ago_time < 0 ? " ahead" : " ago"); } else { ago_str = "just now"; }