Skip to content

Commit

Permalink
Don't use duration formatting for second unit (#23132)
Browse files Browse the repository at this point in the history
Don't use duration formatting for sec unit
  • Loading branch information
piitaya authored Dec 4, 2024
1 parent af1622e commit f8ce7c2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
19 changes: 1 addition & 18 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 = ["s", "min", "h", "d"] as const;
export const DURATION_UNITS = ["min", "h", "d"] as const;

type DurationUnit = (typeof DURATION_UNITS)[number];

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

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

export const formatDuration = (
locale: FrontendLocaleData,
duration: string,
Expand Down Expand Up @@ -146,15 +138,6 @@ export const formatDuration = (
};
return formatDurationMinuteMem(locale).format(input);
}
case "s": {
const seconds = Math.floor(value);
const milliseconds = Math.floor((value - seconds) * 1000);
const input: DurationInput = {
seconds,
milliseconds,
};
return formatDurationSecondMem(locale).format(input);
}
default:
throw new Error("Invalid duration unit");
}
Expand Down
5 changes: 0 additions & 5 deletions test/common/datetime/format_duration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const LOCALE: FrontendLocaleData = {

describe("formatDuration", () => {
it("works", () => {
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");
assert.strictEqual(formatDuration(LOCALE, "65", "s"), "65s");

assert.strictEqual(formatDuration(LOCALE, "0.25", "min"), "0m 15s");
assert.strictEqual(formatDuration(LOCALE, "0.5", "min"), "0m 30s");
assert.strictEqual(formatDuration(LOCALE, "1", "min"), "1m");
Expand Down

0 comments on commit f8ce7c2

Please sign in to comment.