mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-09 19:56:34 +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 { FrontendLocaleData } from "../../data/translation";
|
||||
import { formatListWithAnds } from "../string/format-list";
|
||||
|
||||
const leftPad = (num: number) => (num < 10 ? `0${num}` : num);
|
||||
|
||||
@ -47,58 +47,7 @@ export const formatNumericDuration = (
|
||||
export const formatDurationLong = (
|
||||
locale: FrontendLocaleData,
|
||||
duration: HaDurationData
|
||||
) => {
|
||||
const d = duration.days || 0;
|
||||
const h = duration.hours || 0;
|
||||
const m = duration.minutes || 0;
|
||||
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);
|
||||
};
|
||||
) =>
|
||||
new DurationFormat(locale.language, {
|
||||
style: "long",
|
||||
}).format(duration);
|
||||
|
Loading…
x
Reference in New Issue
Block a user