Skip to content
Snippets Groups Projects
Unverified Commit faad557b authored by Dalton's avatar Dalton Committed by GitHub
Browse files

don't show exact seconds for a formatted relative time (#17828)

* don't show exact seconds for a formatted relative time

* add a couple of getRelativeTimeAbbreviated tests
parent bae75e20
No related branches found
No related tags found
No related merge requests found
......@@ -13,8 +13,8 @@ function addAbbreviatedLocale() {
relativeTime: {
future: "in %s",
past: "%s",
s: "%d s",
ss: "%d s",
s: t`just now`,
ss: t`just now`,
m: "%d m",
mm: "%d m",
h: "%d h",
......
import { parseTime, parseTimestamp } from "metabase/lib/time";
import {
parseTime,
parseTimestamp,
getRelativeTimeAbbreviated,
} from "metabase/lib/time";
import moment from "moment";
describe("time", () => {
......@@ -65,4 +69,34 @@ describe("time", () => {
expect(result.format("h:mm A")).toBe("1:02 AM");
});
});
describe("getRelativeTimeAbbreviated", () => {
it("should show 'just now' for timestamps from the immediate past", () => {
expect(
getRelativeTimeAbbreviated(
moment()
.subtract(30, "s")
.toString(),
),
).toEqual("just now");
});
it("should show a shortened string for times 1 minute+", () => {
expect(
getRelativeTimeAbbreviated(
moment()
.subtract(61, "s")
.toString(),
),
).toEqual("1 m");
expect(
getRelativeTimeAbbreviated(
moment()
.subtract(5, "d")
.toString(),
),
).toEqual("5 d");
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment