-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
445d470
commit 5bccb5c
Showing
1 changed file
with
6 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import type { Composer } from "vue-i18n"; | ||
|
||
export function lastUpdated(date: Date | string, i18n?: Composer): string { | ||
i18n = i18n ?? useI18n(); | ||
// some dum linter hates me | ||
const lang = (i18n ?? useI18n())!; | ||
date = new Date(date); | ||
const today: Date = new Date(); | ||
const todayTime = today.getTime(); | ||
const dateTime = date.getTime(); | ||
const todayDays = Math.floor(todayTime / (1000 * 60 * 60 * 24)); | ||
const dateDays = Math.floor(dateTime / (1000 * 60 * 60 * 24)); | ||
if (todayDays === dateDays) { | ||
return i18n.t("general.today") + " " + i18n.d(date, "clock"); | ||
return lang.t("general.today") + " " + lang.d(date, "clock"); | ||
} else if (todayDays === dateDays + 1) { | ||
return i18n.t("general.yesterday") + " " + i18n.d(date, "clock"); | ||
return lang.t("general.yesterday") + " " + lang.d(date, "clock"); | ||
} else if (todayDays - dateDays < 7) { | ||
return i18n.d(date, "shortweektime"); | ||
return lang.d(date, "shortweektime"); | ||
} else { | ||
return i18n.d(date, "date"); | ||
return lang.d(date, "date"); | ||
} | ||
} |