From b6d5556561698579361db9158d1ad70c5a8d48a4 Mon Sep 17 00:00:00 2001
From: JD Hartley <jdhartley@users.noreply.github.com>
Date: Tue, 31 Dec 2024 04:22:50 -0600
Subject: feat: show createdAt year in card footer when created over a year ago
 (#790)

---
 .../dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx        | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx')

diff --git a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx
index 1df0c197..a2323987 100644
--- a/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx
+++ b/apps/web/components/dashboard/bookmarks/BookmarkLayoutAdaptingCard.tsx
@@ -30,6 +30,13 @@ interface Props {
   wrapTags: boolean;
 }
 
+function BookmarkFormattedCreatedAt({ bookmark }: { bookmark: ZBookmark }) {
+  const createdAt = dayjs(bookmark.createdAt);
+  const oneYearAgo = dayjs().subtract(1, "year");
+  const formatString = createdAt.isAfter(oneYearAgo) ? "MMM D" : "MMM D, YYYY";
+  return createdAt.format(formatString);
+}
+
 function BottomRow({
   footer,
   bookmark,
@@ -45,7 +52,7 @@ function BottomRow({
           href={`/dashboard/preview/${bookmark.id}`}
           suppressHydrationWarning
         >
-          {dayjs(bookmark.createdAt).format("MMM DD")}
+          <BookmarkFormattedCreatedAt bookmark={bookmark} />
         </Link>
       </div>
       <BookmarkActionBar bookmark={bookmark} />
@@ -232,7 +239,7 @@ function CompactView({ bookmark, title, footer, className }: Props) {
             suppressHydrationWarning
             className="shrink-0 gap-2 text-gray-500"
           >
-            {dayjs(bookmark.createdAt).format("MMM DD")}
+            <BookmarkFormattedCreatedAt bookmark={bookmark} />
           </Link>
         </div>
         <BookmarkActionBar bookmark={bookmark} />
-- 
cgit v1.2.3-70-g09d2

