initial commit

This commit is contained in:
2025-06-18 07:46:59 -04:00
commit 9a82d1a664
167 changed files with 40539 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
---
interface Props {
date: Date | string;
includeRelative?: boolean;
}
const { date, includeRelative = false } = Astro.props;
const formatDate = (date: Date | string, includeRelative: boolean): string => {
let currentDate = new Date();
let targetDate = date instanceof Date ? date : new Date(date);
if (isNaN(targetDate.getTime())) {
console.error("Invalid date:", date);
return "Invalid Date";
}
let yearsAgo = currentDate.getFullYear() - targetDate.getFullYear();
let monthsAgo = currentDate.getMonth() - targetDate.getMonth();
let daysAgo = currentDate.getDate() - targetDate.getDate();
let formattedDate = "";
if (yearsAgo > 0) {
formattedDate = `${yearsAgo}y ago`;
} else if (monthsAgo > 0) {
formattedDate = `${monthsAgo}mo ago`;
} else if (daysAgo > 0) {
formattedDate = `${daysAgo}d ago`;
} else {
formattedDate = "Today";
}
let fullDate = targetDate.toLocaleString("en-us", {
month: "short",
day: "numeric",
year: "numeric",
});
if (!includeRelative) {
return fullDate;
}
return `${fullDate} (${formattedDate})`;
};
const formattedDateString = formatDate(date, includeRelative);
---
<time datetime={new Date(date).toISOString()}>
{formattedDateString}
</time>