Skip to content
Permalink
Browse files

UX: Use medium format for displaying time in post notices. (#8074)

  • Loading branch information...
udan11 committed Sep 11, 2019
1 parent 5da7ffd commit 8b2c272f04632e048b4c572c0b498eb926c7c459
@@ -262,7 +262,7 @@ function relativeAgeTinyShowsYear(relativeAgeString) {
return relativeAgeString.match(/'[\d]{2}$/);
}

function relativeAgeMediumSpan(distance, leaveAgo) {
export function relativeAgeMediumSpan(distance, leaveAgo) {
let formatted;
const distanceInMinutes = Math.round(distance / 60.0);

@@ -283,14 +283,24 @@ function relativeAgeMediumSpan(distance, leaveAgo) {
case distanceInMinutes >= 90 && distanceInMinutes <= 1409:
formatted = t("x_hours", { count: Math.round(distanceInMinutes / 60.0) });
break;
case distanceInMinutes >= 1410 && distanceInMinutes <= 2159:
case distanceInMinutes >= 1410 && distanceInMinutes <= 2519:
formatted = t("x_days", { count: 1 });
break;
case distanceInMinutes >= 2160:
case distanceInMinutes >= 2520 && distanceInMinutes <= 129599:
formatted = t("x_days", {
count: Math.round((distanceInMinutes - 720.0) / 1440.0)
});
break;
case distanceInMinutes >= 129600 && distanceInMinutes <= 525599:
formatted = t("x_months", {
count: Math.round(distanceInMinutes / 43200.0)
});
break;
default:
formatted = t("x_years", {
count: Math.round(distanceInMinutes / 525600.0)
});
break;
}
return formatted || "&mdash;";
}
@@ -14,7 +14,7 @@ import {
formatUsername
} from "discourse/lib/utilities";
import hbs from "discourse/widgets/hbs-compiler";
import { durationTiny } from "discourse/lib/formatter";
import { relativeAgeMediumSpan } from "discourse/lib/formatter";
import { prioritizeNameInUx } from "discourse/lib/settings";

function transformWithCallbacks(post) {
@@ -472,7 +472,7 @@ createWidget("post-notice", {
"p",
I18n.t("post.notice.returning_user", {
user,
time: durationTiny(distance, { addAgo: true })
time: relativeAgeMediumSpan(distance, true)
})
);
}
@@ -124,6 +124,12 @@ en:
x_days:
one: "%{count} day ago"
other: "%{count} days ago"
x_months:
one: "%{count} month ago"
other: "%{count} months ago"
x_years:
one: "%{count} year ago"
other: "%{count} years ago"
later:
x_days:
one: "%{count} day later"
@@ -893,7 +893,7 @@ widgetTest("post notice - with username", {
.trim(),
I18n.t("post.notice.returning_user", {
user: "codinghorror",
time: "2d ago"
time: "2 days ago"
})
);
}

0 comments on commit 8b2c272

Please sign in to comment.
You can’t perform that action at this time.