From cd69cba3f0416791a5fb665a1e8132a95b9a7903 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 15 Oct 2015 13:26:52 +0200 Subject: [PATCH] Improved pretty date (just now). --- .../javascripts/app/lib/app_post/pretty_date.coffee | 3 +++ public/assets/tests/ui.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/pretty_date.coffee b/app/assets/javascripts/app/lib/app_post/pretty_date.coffee index 8866818fd..69a8b05f3 100644 --- a/app/assets/javascripts/app/lib/app_post/pretty_date.coffee +++ b/app/assets/javascripts/app/lib/app_post/pretty_date.coffee @@ -26,6 +26,9 @@ class App.PrettyDate diff = diff.toString().replace('-', '') diff = parseFloat(diff) + if diff < 60 + return App.i18n.translateInline('just now') + if direction is 'past' && !escalation && diff > ( 60 * 60 * 24 * 14 ) return App.i18n.translateDate(time) diff --git a/public/assets/tests/ui.js b/public/assets/tests/ui.js index cb7297236..ae225d4d0 100644 --- a/public/assets/tests/ui.js +++ b/public/assets/tests/ui.js @@ -5,7 +5,10 @@ test( "check pretty date", function() { // past var result = App.PrettyDate.humanTime( current ); - equal( result, '0 minutes ago', 'right now') + equal( result, 'just now', 'just now') + + result = App.PrettyDate.humanTime( current - 15000 ); + equal( result, 'just now', 'just now') result = App.PrettyDate.humanTime( current - 60000 ); equal( result, '1 minute ago', '1 min ago') @@ -60,7 +63,10 @@ test( "check pretty date", function() { // future current = new Date() result = App.PrettyDate.humanTime( current ); - equal( result, '0 minutes ago', 'right now') + equal( result, 'just now', 'just now') + + result = App.PrettyDate.humanTime( current.getTime() + 55000 ); + equal( result, 'just now', 'just now') result = App.PrettyDate.humanTime( current.getTime() + 65000 ); equal( result, 'in 1 minute', 'in 1 min')