feat: more readable time delta #193
1 changed files with 29 additions and 1 deletions
|
@ -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", () => {
|
describe("Date with correct timezone", () => {
|
||||||
const map = new Map([["u_time_at", "@"]]);
|
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/);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue