Add weekday to formatTimeWeekday() (#11020)

This commit is contained in:
Michael Gorven 2022-01-24 10:25:45 -08:00 committed by GitHub
parent e57477c16a
commit 1010777139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -43,9 +43,9 @@ export const formatTimeWeekday = (dateObj: Date, locale: FrontendLocaleData) =>
const formatTimeWeekdayMem = memoizeOne(
(locale: FrontendLocaleData) =>
new Intl.DateTimeFormat(locale.language, {
weekday: "long",
hour: useAmPm(locale) ? "numeric" : "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: useAmPm(locale),
})
);

View File

@ -3,6 +3,7 @@ import { assert } from "chai";
import {
formatTime,
formatTimeWithSeconds,
formatTimeWeekday,
} from "../../../src/common/datetime/format_time";
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"
);
});
});