mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-24 20:55:49 +00:00
Use browser default time and number formatting with polyfills if needed (#9481)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
53
test/common/datetime/format_time.ts
Normal file
53
test/common/datetime/format_time.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { assert } from "chai";
|
||||
|
||||
import {
|
||||
formatTime,
|
||||
formatTimeWithSeconds,
|
||||
} from "../../../src/common/datetime/format_time";
|
||||
import { NumberFormat, TimeFormat } from "../../../src/data/translation";
|
||||
|
||||
describe("formatTime", () => {
|
||||
const dateObj = new Date(2017, 10, 18, 23, 12, 13, 1400);
|
||||
|
||||
it("Formats English times", () => {
|
||||
assert.strictEqual(
|
||||
formatTime(dateObj, {
|
||||
language: "en",
|
||||
number_format: NumberFormat.language,
|
||||
time_format: TimeFormat.am_pm,
|
||||
}),
|
||||
"11:12 PM"
|
||||
);
|
||||
assert.strictEqual(
|
||||
formatTime(dateObj, {
|
||||
language: "en",
|
||||
number_format: NumberFormat.language,
|
||||
time_format: TimeFormat.twenty_four,
|
||||
}),
|
||||
"23:12"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatTimeWithSeconds", () => {
|
||||
const dateObj = new Date(2017, 10, 18, 23, 12, 13, 400);
|
||||
|
||||
it("Formats English times with seconds", () => {
|
||||
assert.strictEqual(
|
||||
formatTimeWithSeconds(dateObj, {
|
||||
language: "en",
|
||||
number_format: NumberFormat.language,
|
||||
time_format: TimeFormat.am_pm,
|
||||
}),
|
||||
"11:12:13 PM"
|
||||
);
|
||||
assert.strictEqual(
|
||||
formatTimeWithSeconds(dateObj, {
|
||||
language: "en",
|
||||
number_format: NumberFormat.language,
|
||||
time_format: TimeFormat.twenty_four,
|
||||
}),
|
||||
"23:12:13"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user