mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-14 06:06:33 +00:00
parent
a532b4461d
commit
2782b2fb1b
@ -1,6 +1,6 @@
|
|||||||
|
import { DurationFormat } from "@formatjs/intl-durationformat";
|
||||||
import type { HaDurationData } from "../../components/ha-duration-input";
|
import type { HaDurationData } from "../../components/ha-duration-input";
|
||||||
import type { FrontendLocaleData } from "../../data/translation";
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import { formatListWithAnds } from "../string/format-list";
|
|
||||||
|
|
||||||
const leftPad = (num: number) => (num < 10 ? `0${num}` : num);
|
const leftPad = (num: number) => (num < 10 ? `0${num}` : num);
|
||||||
|
|
||||||
@ -47,58 +47,7 @@ export const formatNumericDuration = (
|
|||||||
export const formatDurationLong = (
|
export const formatDurationLong = (
|
||||||
locale: FrontendLocaleData,
|
locale: FrontendLocaleData,
|
||||||
duration: HaDurationData
|
duration: HaDurationData
|
||||||
) => {
|
) =>
|
||||||
const d = duration.days || 0;
|
new DurationFormat(locale.language, {
|
||||||
const h = duration.hours || 0;
|
style: "long",
|
||||||
const m = duration.minutes || 0;
|
}).format(duration);
|
||||||
const s = duration.seconds || 0;
|
|
||||||
const ms = duration.milliseconds || 0;
|
|
||||||
|
|
||||||
const parts: string[] = [];
|
|
||||||
if (d > 0) {
|
|
||||||
parts.push(
|
|
||||||
Intl.NumberFormat(locale.language, {
|
|
||||||
style: "unit",
|
|
||||||
unit: "day",
|
|
||||||
unitDisplay: "long",
|
|
||||||
}).format(d)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (h > 0) {
|
|
||||||
parts.push(
|
|
||||||
Intl.NumberFormat(locale.language, {
|
|
||||||
style: "unit",
|
|
||||||
unit: "hour",
|
|
||||||
unitDisplay: "long",
|
|
||||||
}).format(h)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (m > 0) {
|
|
||||||
parts.push(
|
|
||||||
Intl.NumberFormat(locale.language, {
|
|
||||||
style: "unit",
|
|
||||||
unit: "minute",
|
|
||||||
unitDisplay: "long",
|
|
||||||
}).format(m)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (s > 0) {
|
|
||||||
parts.push(
|
|
||||||
Intl.NumberFormat(locale.language, {
|
|
||||||
style: "unit",
|
|
||||||
unit: "second",
|
|
||||||
unitDisplay: "long",
|
|
||||||
}).format(s)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (ms > 0) {
|
|
||||||
parts.push(
|
|
||||||
Intl.NumberFormat(locale.language, {
|
|
||||||
style: "unit",
|
|
||||||
unit: "millisecond",
|
|
||||||
unitDisplay: "long",
|
|
||||||
}).format(ms)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return formatListWithAnds(locale, parts);
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user