Change option in web

This commit is contained in:
Nick Mowen 2023-02-23 07:05:55 -07:00
parent 58f2fae28e
commit 7dbca95a9a

View File

@ -37,14 +37,14 @@ export const getNowYesterdayInLong = (): number => {
*/ */
interface DateTimeStyle { interface DateTimeStyle {
timezone: string; timezone: string;
use12hour: boolean | undefined; time_format: 'browser' | '12hour' | '24hour';
date_style: 'full' | 'long' | 'medium' | 'short'; date_style: 'full' | 'long' | 'medium' | 'short';
time_style: 'full' | 'long' | 'medium' | 'short'; time_style: 'full' | 'long' | 'medium' | 'short';
strftime_fmt: string; strftime_fmt: string;
} }
export const formatUnixTimestampToDateTime = (unixTimestamp: number, config: DateTimeStyle): string => { export const formatUnixTimestampToDateTime = (unixTimestamp: number, config: DateTimeStyle): string => {
const { timezone, use12hour, date_style, time_style, strftime_fmt } = config; const { timezone, time_format, date_style, time_style, strftime_fmt } = config;
const locale = window.navigator?.language || 'en-US'; const locale = window.navigator?.language || 'en-US';
if (isNaN(unixTimestamp)) { if (isNaN(unixTimestamp)) {
@ -64,7 +64,7 @@ export const formatUnixTimestampToDateTime = (unixTimestamp: number, config: Dat
dateStyle: date_style, dateStyle: date_style,
timeStyle: time_style, timeStyle: time_style,
timeZone: timezone || Intl.DateTimeFormat().resolvedOptions().timeZone, timeZone: timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
hour12: use12hour !== null ? use12hour : undefined, hour12: time_format !== 'browser' ? time_format == '12hour' : undefined,
}); });
return formatter.format(date); return formatter.format(date);
} catch (error) { } catch (error) {