Show day counts in call durations (#9641)
* Show day counts in call durations Previously call durations over a day long would be truncated, for example displaying as '2h 0m 0s' instead of '1d 2h 0m 0s'. * Fix strict mode errors * Fix strings Co-authored-by: Travis Ralston <travisr@matrix.org>
This commit is contained in:
parent
440f76c3e8
commit
69e03860a0
6 changed files with 55 additions and 25 deletions
|
@ -20,6 +20,7 @@ import {
|
|||
formatDuration,
|
||||
formatFullDateNoDayISO,
|
||||
formatTimeLeft,
|
||||
formatPreciseDuration,
|
||||
} from "../../src/DateUtils";
|
||||
import { REPEATABLE_DATE } from "../test-utils";
|
||||
|
||||
|
@ -100,6 +101,22 @@ describe('formatDuration()', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("formatPreciseDuration", () => {
|
||||
const MINUTE_MS = 1000 * 60;
|
||||
const HOUR_MS = MINUTE_MS * 60;
|
||||
const DAY_MS = HOUR_MS * 24;
|
||||
|
||||
it.each<[string, string, number]>([
|
||||
['3 days, 6 hours, 48 minutes, 59 seconds', '3d 6h 48m 59s', 3 * DAY_MS + 6 * HOUR_MS + 48 * MINUTE_MS + 59000],
|
||||
['6 hours, 48 minutes, 59 seconds', '6h 48m 59s', 6 * HOUR_MS + 48 * MINUTE_MS + 59000],
|
||||
['48 minutes, 59 seconds', '48m 59s', 48 * MINUTE_MS + 59000],
|
||||
['59 seconds', '59s', 59000],
|
||||
['0 seconds', '0s', 0],
|
||||
])('%s formats to %s', (_description, expectedResult, input) => {
|
||||
expect(formatPreciseDuration(input)).toEqual(expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatFullDateNoDayISO", () => {
|
||||
it("should return ISO format", () => {
|
||||
expect(formatFullDateNoDayISO(REPEATABLE_DATE)).toEqual("2022-11-17T16:58:32.517Z");
|
||||
|
@ -108,7 +125,6 @@ describe("formatFullDateNoDayISO", () => {
|
|||
|
||||
describe("formatTimeLeft", () => {
|
||||
it.each([
|
||||
[null, "0s left"],
|
||||
[0, "0s left"],
|
||||
[23, "23s left"],
|
||||
[60 + 23, "1m 23s left"],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue