UX: Use medium format for displaying time in post notices. (#8074)
This commit is contained in:
parent
5da7ffd46c
commit
8b2c272f04
|
@ -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 || "—";
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue