Skip to content

Commit

Permalink
feat: show createdAt year in card footer when created over a year ago (
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhartley authored Dec 31, 2024
1 parent 61ab59a commit b6d5556
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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} />
Expand Down Expand Up @@ -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} />
Expand Down

0 comments on commit b6d5556

Please sign in to comment.