feat: more readable time delta #193

Merged
Anri merged 6 commits from date into dev 2024-10-08 20:53:29 +02:00
Showing only changes of commit bfc3b008cc - Show all commits

View file

@ -1,4 +1,10 @@
import { nextTimeUnit, showDate, strToSeconds, TimeSecond } from "../../utils/time";
import {
nextTimeUnit,
showDate,
strToSeconds,
timeDeltaToString,
TimeSecond,
} from "../../utils/time";
describe("Date with correct timezone", () => {
const map = new Map([["u_time_at", "@"]]);
@ -84,3 +90,25 @@ describe("Next time unit", () => {
});
}
});
describe("Relative time", () => {
// Thoses tests are based on time, we have 10s of acceptance.
{
const name = Date.now() + (10 * TimeSecond.Minute + 30) * 1000;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toMatch(/10m 30s|10m 2\ds/);
});
}
{
const name = Date.now() + (12 * TimeSecond.Hour + 30 * TimeSecond.Minute) * 1000;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toMatch(/12h 30m|12h 29m 5\ds/);
});
}
{
const name = Date.now() + (TimeSecond.Week + TimeSecond.Day + 6 * TimeSecond.Hour) * 1000;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toMatch(/1w 1d 6h|1w 1d 5h 59m 5\ds/);
});
}
});