mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 10:59:50 +00:00
Show seconds in the UI (#4765)
This commit is contained in:
committed by
GitHub
parent
2e47aa1905
commit
c977f22047
@@ -1,16 +1,7 @@
|
||||
import fecha from "fecha";
|
||||
import { toLocaleStringSupportsOptions } from "./check_options_support";
|
||||
|
||||
// Check for support of native locale string options
|
||||
function toLocaleStringSupportsOptions() {
|
||||
try {
|
||||
new Date().toLocaleString("i");
|
||||
} catch (e) {
|
||||
return e.name === "RangeError";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export default toLocaleStringSupportsOptions()
|
||||
export const formatDateTime = toLocaleStringSupportsOptions
|
||||
? (dateObj: Date, locales: string) =>
|
||||
dateObj.toLocaleString(locales, {
|
||||
year: "numeric",
|
||||
@@ -19,4 +10,24 @@ export default toLocaleStringSupportsOptions()
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
})
|
||||
: (dateObj: Date) => fecha.format(dateObj, "haDateTime");
|
||||
: (dateObj: Date) =>
|
||||
fecha.format(
|
||||
dateObj,
|
||||
`${fecha.masks.longDate}, ${fecha.masks.shortTime}`
|
||||
);
|
||||
|
||||
export const formatDateTimeWithSeconds = toLocaleStringSupportsOptions
|
||||
? (dateObj: Date, locales: string) =>
|
||||
dateObj.toLocaleString(locales, {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
})
|
||||
: (dateObj: Date) =>
|
||||
fecha.format(
|
||||
dateObj,
|
||||
`${fecha.masks.longDate}, ${fecha.masks.mediumTime}`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user