rework the formatRelativeDate function

This commit is contained in:
m5r 2021-09-07 03:37:06 +08:00
parent 3433a90258
commit 48f9e67516

View File

@ -27,9 +27,13 @@ export function formatTime(date: Date, config?: Intl.DateTimeFormatOptions): str
export function formatRelativeDate(date: Date): string {
const dateTime = DateTime.fromJSDate(date);
const now = new Date();
const diff = dateTime.diffNow("days");
const isToday = diff.days >= -1;
const isToday =
date.getDate() === now.getDate() &&
date.getMonth() === now.getMonth() &&
date.getFullYear() === now.getFullYear();
if (isToday) {
return dateTime.toFormat("HH:mm", { locale: "en-US" });
}