From 33feb626738d49c773b3f27b87ad968a7d34d25c Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Tue, 21 Nov 2017 14:33:39 -0500 Subject: [PATCH] FIX: times showing as < 1m instead of blank --- app/assets/javascripts/discourse/lib/formatter.js.es6 | 2 ++ test/javascripts/lib/formatter-test.js.es6 | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/assets/javascripts/discourse/lib/formatter.js.es6 b/app/assets/javascripts/discourse/lib/formatter.js.es6 index 07b8a2153f8..b26b270b2cc 100644 --- a/app/assets/javascripts/discourse/lib/formatter.js.es6 +++ b/app/assets/javascripts/discourse/lib/formatter.js.es6 @@ -130,6 +130,8 @@ function wrapAgo(dateStr) { } export function durationTiny(distance, ageOpts) { + if (typeof(distance) !== 'number') { return '—'; } + const dividedDistance = Math.round(distance / 60.0); const distanceInMinutes = (dividedDistance < 1) ? 1 : dividedDistance; diff --git a/test/javascripts/lib/formatter-test.js.es6 b/test/javascripts/lib/formatter-test.js.es6 index 7856c9b9585..1d3d4e43fc1 100644 --- a/test/javascripts/lib/formatter-test.js.es6 +++ b/test/javascripts/lib/formatter-test.js.es6 @@ -214,6 +214,8 @@ QUnit.test("number", assert => { }); QUnit.test("durationTiny", assert => { + assert.equal(durationTiny(), '—', "undefined is a dash"); + assert.equal(durationTiny(null), '—', "null is a dash"); assert.equal(durationTiny(0), '< 1m', "0 seconds shows as < 1m"); assert.equal(durationTiny(59), '< 1m', "59 seconds shows as < 1m"); assert.equal(durationTiny(60), '1m', "60 seconds shows as 1m");