Skip to content

Commit

Permalink
Dont floor duration for milliseconds (#23028)
Browse files Browse the repository at this point in the history
* Dont floor duration for milliseconds

* remove ms
  • Loading branch information
karwosts authored Nov 27, 2024
1 parent 3411967 commit f7c8c6e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
17 changes: 1 addition & 16 deletions src/common/datetime/format_duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const formatDurationDigital = (
duration: HaDurationData
) => formatDigitalDurationMem(locale).format(duration);

export const DURATION_UNITS = ["ms", "s", "min", "h", "d"] as const;
export const DURATION_UNITS = ["s", "min", "h", "d"] as const;

type DurationUnit = (typeof DURATION_UNITS)[number];

Expand Down Expand Up @@ -107,14 +107,6 @@ const formatDurationSecondMem = memoizeOne(
})
);

const formatDurationMillisecondMem = memoizeOne(
(locale: FrontendLocaleData) =>
new Intl.DurationFormat(locale.language, {
style: "narrow",
millisecondsDisplay: "always",
})
);

export const formatDuration = (
locale: FrontendLocaleData,
duration: string,
Expand Down Expand Up @@ -163,13 +155,6 @@ export const formatDuration = (
};
return formatDurationSecondMem(locale).format(input);
}
case "ms": {
const milliseconds = Math.floor(value);
const input: DurationInput = {
milliseconds,
};
return formatDurationMillisecondMem(locale).format(input);
}
default:
throw new Error("Invalid duration unit");
}
Expand Down
8 changes: 0 additions & 8 deletions test/common/datetime/format_duration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ const LOCALE: FrontendLocaleData = {

describe("formatDuration", () => {
it("works", () => {
assert.strictEqual(formatDuration(LOCALE, "0", "ms"), "0ms");
assert.strictEqual(formatDuration(LOCALE, "1", "ms"), "1ms");
assert.strictEqual(formatDuration(LOCALE, "10", "ms"), "10ms");
assert.strictEqual(formatDuration(LOCALE, "100", "ms"), "100ms");
assert.strictEqual(formatDuration(LOCALE, "1000", "ms"), "1,000ms");
assert.strictEqual(formatDuration(LOCALE, "1001", "ms"), "1,001ms");
assert.strictEqual(formatDuration(LOCALE, "65000", "ms"), "65,000ms");

assert.strictEqual(formatDuration(LOCALE, "0.5", "s"), "0s 500ms");
assert.strictEqual(formatDuration(LOCALE, "1", "s"), "1s");
assert.strictEqual(formatDuration(LOCALE, "1.1", "s"), "1s 100ms");
Expand Down

0 comments on commit f7c8c6e

Please sign in to comment.