forked from mirrors/homebox
fix datetime display issues (again) (#324)
This commit is contained in:
parent
025521431e
commit
cf536393f5
8 changed files with 46 additions and 14 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue