Skip to content

Commit 048124a

Browse files
committed
adjust date
1 parent df5f0d0 commit 048124a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

apps/web/app/(app)/automation/group/ViewGroup.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
import { isActionError } from "@/utils/error";
4242
import { Badge } from "@/components/ui/badge";
4343
import { formatShortDate } from "@/utils/date";
44+
import { Tooltip } from "@/components/Tooltip";
4445

4546
export function ViewGroup({ groupId }: { groupId: string }) {
4647
const { data, isLoading, error, mutate } = useSWR<GroupItemsResponse>(
@@ -269,7 +270,7 @@ function GroupItemList({
269270
</TableHeader>
270271
)}
271272
<TableBody>
272-
{sortBy(items, (item) => -item.createdAt).map((item) => {
273+
{sortBy(items, (item) => -new Date(item.createdAt)).map((item) => {
273274
const twoMinutesAgo = new Date(Date.now() - 1000 * 60 * 2);
274275
const isCreatedRecently = new Date(item.createdAt) > twoMinutesAgo;
275276
const isUpdatedRecently = new Date(item.updatedAt) > twoMinutesAgo;
@@ -291,9 +292,11 @@ function GroupItemList({
291292
</div>
292293
</TableCell>
293294
<TableCell className="py-2 text-right flex justify-end items-center gap-4">
294-
<span className="text-sm text-muted-foreground">
295-
Added: {formatShortDate(new Date(item.createdAt))}
296-
</span>
295+
<Tooltip content="Date added">
296+
<span className="text-sm text-muted-foreground">
297+
{formatShortDate(new Date(item.createdAt))}
298+
</span>
299+
</Tooltip>
297300

298301
<Button
299302
variant="outline"

apps/web/utils/date.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export const ONE_DAY_MS = ONE_HOUR_MS * 24;
77
export const ONE_MONTH_MS = ONE_DAY_MS * 30;
88
export const ONE_YEAR_MS = ONE_DAY_MS * 365;
99

10+
/**
11+
* Formats a date into a short string.
12+
* - If the date is today, returns the time (e.g., "3:44 PM").
13+
* - If the date is not today, returns the date (e.g., "JUL 5" or "AUG 13").
14+
* - Optionally includes the year (e.g., "JUL 5, 2024").
15+
* - Optionally returns the date part in lowercase (e.g., "jul 5").
16+
*/
1017
export function formatShortDate(
1118
date: Date,
1219
options: {
@@ -28,7 +35,8 @@ export function formatShortDate(
2835
date.getFullYear() === today.getFullYear();
2936

3037
if (isToday) {
31-
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
38+
// Use hour: 'numeric' to avoid leading zeros (e.g., 3:44 PM instead of 03:44 PM)
39+
return date.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
3240
}
3341
const formattedDate = date.toLocaleDateString([], {
3442
month: "short",

0 commit comments

Comments
 (0)