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

This commit is contained in:
Dan Ungureanu 2019-09-11 13:00:53 +03:00 committed by GitHub
parent 5da7ffd46c
commit 8b2c272f04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 6 deletions

View File

@ -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;";
}

View File

@ -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)
})
);
}

View File

@ -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"

View File

@ -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"
})
);
}