Get chat view started

This commit is contained in:
Jon Staab
2024-08-15 14:30:55 -07:00
parent 184634c6e8
commit 437cfa7bc4
10 changed files with 195 additions and 20 deletions
+30
View File
@@ -60,3 +60,33 @@ export const createSearch = <V, T>(data: T[], opts: SearchOptions<V, T>) => {
searchValues: (term: string) => search(term).map(opts.getValue),
}
}
export const secondsToDate = (ts: number) => new Date(ts * 1000)
export const dateToSeconds = (date: Date) => Math.round(date.valueOf() / 1000)
export const getTimeZone = () => new Date().toString().match(/GMT[^\s]+/)
export const createLocalDate = (dateString: any) => new Date(`${dateString} ${getTimeZone()}`)
export const getLocale = () => new Intl.DateTimeFormat().resolvedOptions().locale
export const formatTimestamp = (ts: number) => {
const formatter = new Intl.DateTimeFormat(getLocale(), {
dateStyle: "short",
timeStyle: "short",
})
return formatter.format(secondsToDate(ts))
}
export const formatTimestampAsDate = (ts: number) => {
const formatter = new Intl.DateTimeFormat(getLocale(), {
year: "numeric",
month: "long",
day: "numeric",
})
return formatter.format(secondsToDate(ts))
}