fix datetime display issues (again) (#324)

This commit is contained in:
Hayden 2023-02-27 19:52:56 -09:00 committed by GitHub
parent 025521431e
commit cf536393f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 14 deletions

View file

@ -21,6 +21,7 @@ export async function useFormatCurrency() {
}
export type DateTimeFormat = "relative" | "long" | "short" | "human";
export type DateTimeType = "date" | "time" | "datetime";
function ordinalIndicator(num: number) {
if (num > 3 && num < 21) return "th";
@ -36,7 +37,7 @@ function ordinalIndicator(num: number) {
}
}
export function fmtDate(value: string | Date, fmt: DateTimeFormat = "human"): string {
export function fmtDate(value: string | Date, fmt: DateTimeFormat = "human", fmtType: DateTimeType): string {
const months = [
"January",
"February",
@ -61,6 +62,11 @@ export function fmtDate(value: string | Date, fmt: DateTimeFormat = "human"): st
return "";
}
if (fmtType === "date") {
// Offset local time
dt.setHours(dt.getHours() + dt.getTimezoneOffset() / 60);
}
switch (fmt) {
case "relative":
return useTimeAgo(dt).value + useDateFormat(dt, " (YYYY-MM-DD)").value;