mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-10 19:06:36 +00:00
Dont floor duration for milliseconds (#23028)
* Dont floor duration for milliseconds * remove ms
This commit is contained in:
parent
3411967fd9
commit
f7c8c6e3e8
@ -71,7 +71,7 @@ export const formatDurationDigital = (
|
|||||||
duration: HaDurationData
|
duration: HaDurationData
|
||||||
) => formatDigitalDurationMem(locale).format(duration);
|
) => 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];
|
type DurationUnit = (typeof DURATION_UNITS)[number];
|
||||||
|
|
||||||
@ -107,14 +107,6 @@ const formatDurationSecondMem = memoizeOne(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const formatDurationMillisecondMem = memoizeOne(
|
|
||||||
(locale: FrontendLocaleData) =>
|
|
||||||
new Intl.DurationFormat(locale.language, {
|
|
||||||
style: "narrow",
|
|
||||||
millisecondsDisplay: "always",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export const formatDuration = (
|
export const formatDuration = (
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
duration: string,
|
duration: string,
|
||||||
@ -163,13 +155,6 @@ export const formatDuration = (
|
|||||||
};
|
};
|
||||||
return formatDurationSecondMem(locale).format(input);
|
return formatDurationSecondMem(locale).format(input);
|
||||||
}
|
}
|
||||||
case "ms": {
|
|
||||||
const milliseconds = Math.floor(value);
|
|
||||||
const input: DurationInput = {
|
|
||||||
milliseconds,
|
|
||||||
};
|
|
||||||
return formatDurationMillisecondMem(locale).format(input);
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Invalid duration unit");
|
throw new Error("Invalid duration unit");
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,6 @@ const LOCALE: FrontendLocaleData = {
|
|||||||
|
|
||||||
describe("formatDuration", () => {
|
describe("formatDuration", () => {
|
||||||
it("works", () => {
|
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, "0.5", "s"), "0s 500ms");
|
||||||
assert.strictEqual(formatDuration(LOCALE, "1", "s"), "1s");
|
assert.strictEqual(formatDuration(LOCALE, "1", "s"), "1s");
|
||||||
assert.strictEqual(formatDuration(LOCALE, "1.1", "s"), "1s 100ms");
|
assert.strictEqual(formatDuration(LOCALE, "1.1", "s"), "1s 100ms");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user