UX: Just show "1m" if less than 1m
This commit is contained in:
parent
fb7409f982
commit
78e8aa823d
|
@ -132,7 +132,8 @@ function wrapAgo(dateStr) {
|
||||||
function relativeAgeTiny(date, ageOpts) {
|
function relativeAgeTiny(date, ageOpts) {
|
||||||
const format = "tiny";
|
const format = "tiny";
|
||||||
const distance = Math.round((new Date() - date) / 1000);
|
const distance = Math.round((new Date() - date) / 1000);
|
||||||
const distanceInMinutes = Math.round(distance / 60.0);
|
const dividedDistance = Math.round(distance / 60.0);
|
||||||
|
const distanceInMinutes = (dividedDistance < 1) ? 1 : dividedDistance;
|
||||||
|
|
||||||
let formatted;
|
let formatted;
|
||||||
const t = function(key, opts) {
|
const t = function(key, opts) {
|
||||||
|
@ -140,11 +141,9 @@ function relativeAgeTiny(date, ageOpts) {
|
||||||
return (ageOpts && ageOpts.addAgo) ? wrapAgo(result) : result;
|
return (ageOpts && ageOpts.addAgo) ? wrapAgo(result) : result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
switch(true) {
|
switch(true) {
|
||||||
case(distanceInMinutes < 1):
|
case(distanceInMinutes >= 0 && distanceInMinutes <= 44):
|
||||||
formatted = t("less_than_x_minutes", {count: 1});
|
|
||||||
break;
|
|
||||||
case(distanceInMinutes >= 1 && distanceInMinutes <= 44):
|
|
||||||
formatted = t("x_minutes", {count: distanceInMinutes});
|
formatted = t("x_minutes", {count: distanceInMinutes});
|
||||||
break;
|
break;
|
||||||
case(distanceInMinutes >= 45 && distanceInMinutes <= 89):
|
case(distanceInMinutes >= 45 && distanceInMinutes <= 89):
|
||||||
|
|
|
@ -74,9 +74,6 @@ en:
|
||||||
x_seconds:
|
x_seconds:
|
||||||
one: "1s"
|
one: "1s"
|
||||||
other: "%{count}s"
|
other: "%{count}s"
|
||||||
less_than_x_minutes:
|
|
||||||
one: "< 1m"
|
|
||||||
other: "< %{count}m"
|
|
||||||
x_minutes:
|
x_minutes:
|
||||||
one: "1m"
|
one: "1m"
|
||||||
other: "%{count}m"
|
other: "%{count}m"
|
||||||
|
|
|
@ -88,7 +88,8 @@ test("formating tiny dates", function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
format = "tiny";
|
format = "tiny";
|
||||||
equal(formatMins(0), "< 1m");
|
equal(formatMins(0), "1m");
|
||||||
|
equal(formatMins(1), "1m");
|
||||||
equal(formatMins(2), "2m");
|
equal(formatMins(2), "2m");
|
||||||
equal(formatMins(60), "1h");
|
equal(formatMins(60), "1h");
|
||||||
equal(formatHours(4), "4h");
|
equal(formatHours(4), "4h");
|
||||||
|
@ -114,7 +115,8 @@ test("formating tiny dates", function() {
|
||||||
equal(formatDays(2), shortDate(2));
|
equal(formatDays(2), shortDate(2));
|
||||||
|
|
||||||
Discourse.SiteSettings.relative_date_duration = 0;
|
Discourse.SiteSettings.relative_date_duration = 0;
|
||||||
equal(formatMins(0), "< 1m");
|
equal(formatMins(0), "1m");
|
||||||
|
equal(formatMins(1), "1m");
|
||||||
equal(formatMins(2), "2m");
|
equal(formatMins(2), "2m");
|
||||||
equal(formatMins(60), "1h");
|
equal(formatMins(60), "1h");
|
||||||
equal(formatDays(1), shortDate(1));
|
equal(formatDays(1), shortDate(1));
|
||||||
|
|
Loading…
Reference in New Issue