mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-04 10:15:22 +03:00
added dateStyle & timeStyle
This commit is contained in:
parent
397e657a0a
commit
952ef7d85d
@ -25,26 +25,27 @@ export const getNowYesterdayInLong = (): number => {
|
|||||||
* @param timezone: string
|
* @param timezone: string
|
||||||
* @returns string - dateTime or 'Invalid time' if unixTimestamp is not provided
|
* @returns string - dateTime or 'Invalid time' if unixTimestamp is not provided
|
||||||
*/
|
*/
|
||||||
export const formatUnixTimestampToDateTime = (
|
interface DateTimeStyle {
|
||||||
unixTimestamp: number,
|
timezone: string;
|
||||||
locale: string,
|
use12hour: boolean | undefined;
|
||||||
timezone: string,
|
dateStyle: 'full' | 'long' | 'medium' | 'short';
|
||||||
use12HourFormat: boolean
|
timeStyle: 'full' | 'long' | 'medium' | 'short';
|
||||||
): string => {
|
}
|
||||||
|
|
||||||
|
export const formatUnixTimestampToDateTime = (unixTimestamp: number, config: DateTimeStyle): string => {
|
||||||
|
const { timezone, use12hour, dateStyle, timeStyle } = config;
|
||||||
|
const locale = window.navigator?.language || 'en-US';
|
||||||
|
|
||||||
if (isNaN(unixTimestamp)) {
|
if (isNaN(unixTimestamp)) {
|
||||||
return 'Invalid time';
|
return 'Invalid time';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const date = new Date(unixTimestamp * 1000);
|
const date = new Date(unixTimestamp * 1000);
|
||||||
const formatter = new Intl.DateTimeFormat(locale, {
|
const formatter = new Intl.DateTimeFormat(locale, {
|
||||||
day: '2-digit',
|
dateStyle,
|
||||||
month: '2-digit',
|
timeStyle,
|
||||||
year: 'numeric',
|
timeZone: timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||||
hour: use12HourFormat ? 'numeric' : '2-digit',
|
hour12: use12hour !== null ? use12hour : undefined,
|
||||||
minute: '2-digit',
|
|
||||||
second: '2-digit',
|
|
||||||
timeZone: timezone,
|
|
||||||
hour12: use12HourFormat !== null ? use12HourFormat : undefined,
|
|
||||||
});
|
});
|
||||||
return formatter.format(date);
|
return formatter.format(date);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user