mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Add weekday to formatTimeWeekday() (#11020)
This commit is contained in:
parent
e57477c16a
commit
1010777139
@ -43,9 +43,9 @@ export const formatTimeWeekday = (dateObj: Date, locale: FrontendLocaleData) =>
|
|||||||
const formatTimeWeekdayMem = memoizeOne(
|
const formatTimeWeekdayMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData) =>
|
(locale: FrontendLocaleData) =>
|
||||||
new Intl.DateTimeFormat(locale.language, {
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
|
weekday: "long",
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
minute: "2-digit",
|
minute: "2-digit",
|
||||||
second: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
hour12: useAmPm(locale),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -3,6 +3,7 @@ import { assert } from "chai";
|
|||||||
import {
|
import {
|
||||||
formatTime,
|
formatTime,
|
||||||
formatTimeWithSeconds,
|
formatTimeWithSeconds,
|
||||||
|
formatTimeWeekday,
|
||||||
} from "../../../src/common/datetime/format_time";
|
} from "../../../src/common/datetime/format_time";
|
||||||
import { NumberFormat, TimeFormat } from "../../../src/data/translation";
|
import { NumberFormat, TimeFormat } from "../../../src/data/translation";
|
||||||
|
|
||||||
@ -51,3 +52,26 @@ describe("formatTimeWithSeconds", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("formatTimeWeekday", () => {
|
||||||
|
const dateObj = new Date(2017, 10, 18, 23, 12, 13, 1400);
|
||||||
|
|
||||||
|
it("Formats English times", () => {
|
||||||
|
assert.strictEqual(
|
||||||
|
formatTimeWeekday(dateObj, {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
}),
|
||||||
|
"Wednesday 11:12 PM"
|
||||||
|
);
|
||||||
|
assert.strictEqual(
|
||||||
|
formatTimeWeekday(dateObj, {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
}),
|
||||||
|
"Wednesday 23:12"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user