From d59abff2d824e88431364b88701d39076b2a5dca Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Sun, 31 Mar 2019 17:49:36 +0300 Subject: [PATCH] UX: Always use relative age for post notices. --- app/assets/javascripts/discourse/widgets/post.js.es6 | 8 +++----- test/javascripts/widgets/post-test.js.es6 | 6 ++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index 167f95c6343..77f3f31abe9 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -13,7 +13,7 @@ import { formatUsername } from "discourse/lib/utilities"; import hbs from "discourse/widgets/hbs-compiler"; -import { relativeAge } from "discourse/lib/formatter"; +import { durationTiny } from "discourse/lib/formatter"; function transformWithCallbacks(post) { let transformed = transformBasicPost(post); @@ -461,12 +461,10 @@ createWidget("post-notice", { text = I18n.t("post.notice.first", { user }); } else if (attrs.postNoticeType === "returning") { icon = "far-smile"; + const distance = (new Date() - new Date(attrs.postNoticeTime)) / 1000; text = I18n.t("post.notice.return", { user, - time: relativeAge(attrs.postNoticeTime, { - format: "tiny", - addAgo: true - }) + time: durationTiny(distance, { addAgo: true }) }); } diff --git a/test/javascripts/widgets/post-test.js.es6 b/test/javascripts/widgets/post-test.js.es6 index 9dc9754aa46..4a722cdc1ed 100644 --- a/test/javascripts/widgets/post-test.js.es6 +++ b/test/javascripts/widgets/post-test.js.es6 @@ -874,11 +874,13 @@ widgetTest("pm map", { widgetTest("post notice - with username", { template: '{{mount-widget widget="post" args=args}}', beforeEach() { + const date_2d_ago = new Date(); + date_2d_ago.setDate(date_2d_ago.getDate() - 2); this.siteSettings.prioritize_username_in_ux = true; this.siteSettings.old_post_notice_days = 14; this.set("args", { postNoticeType: "returning", - postNoticeTime: new Date(2010, 0, 1), + postNoticeTime: date_2d_ago, username: "codinghorror", name: "Jeff", created_at: new Date() @@ -889,7 +891,7 @@ widgetTest("post notice - with username", { find(".post-notice.returning-user:not(.old)") .text() .trim(), - I18n.t("post.notice.return", { user: "codinghorror", time: "Jan '10" }) + I18n.t("post.notice.return", { user: "codinghorror", time: "2d ago" }) ); } });