Skip to content

Commit 94ad759

Browse files
committed
formatDateTimeSmart
1 parent 244abb2 commit 94ad759

6 files changed

Lines changed: 32 additions & 17 deletions

File tree

apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/sales/sale-table.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DICEBEAR_AVATAR_URL,
2525
fetcher,
2626
formatDateTime,
27+
formatDateTimeSmart,
2728
} from "@dub/utils";
2829
import { useParams } from "next/navigation";
2930
import { memo } from "react";
@@ -80,10 +81,7 @@ const SaleTableBusinessInner = memo(
8081
header: "Date",
8182
cell: ({ row }) => (
8283
<p title={formatDateTime(row.original.createdAt)}>
83-
{formatDateTime(row.original.createdAt, {
84-
month: "short",
85-
year: undefined,
86-
})}
84+
{formatDateTimeSmart(row.original.createdAt)}
8785
</p>
8886
),
8987
},

apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-table.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
currencyFormatter,
2222
fetcher,
2323
formatDateTime,
24+
formatDateTimeSmart,
2425
getApexDomain,
2526
getPrettyUrl,
2627
} from "@dub/utils";
@@ -72,10 +73,7 @@ export function EarningsTablePartner({ limit }: { limit?: number }) {
7273
minSize: 140,
7374
cell: ({ row }) => (
7475
<p title={formatDateTime(row.original.createdAt)}>
75-
{formatDateTime(row.original.createdAt, {
76-
month: "short",
77-
year: undefined,
78-
})}
76+
{formatDateTimeSmart(row.original.createdAt)}
7977
</p>
8078
),
8179
},

apps/web/app/partners.dub.co/(dashboard)/settings/payouts/payout-details-sheet.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ import {
2020
currencyFormatter,
2121
DICEBEAR_AVATAR_URL,
2222
fetcher,
23-
} from "@dub/utils";
24-
import {
2523
formatDateTime,
26-
formatPeriod,
27-
} from "@dub/utils/src/functions/datetime";
24+
} from "@dub/utils";
25+
import { formatPeriod } from "@dub/utils/src/functions/datetime";
2826
import Link from "next/link";
2927
import { Dispatch, Fragment, SetStateAction, useMemo } from "react";
3028
import useSWR from "swr";
@@ -192,7 +190,7 @@ function PayoutDetailsSheetContent({
192190
{sales?.length === SHEET_MAX_ITEMS && (
193191
<div className="mt-2 flex justify-end">
194192
<Link
195-
href={`/programs/${payout.program.slug}/sales`}
193+
href={`/programs/${payout.program.slug}/earnings?interval=all&payoutId=${payout.id}`}
196194
target="_blank"
197195
className={cn(
198196
buttonVariants({ variant: "secondary" }),

apps/web/ui/partners/payout-details-sheet.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ import {
1717
currencyFormatter,
1818
DICEBEAR_AVATAR_URL,
1919
fetcher,
20-
} from "@dub/utils";
21-
import {
2220
formatDateTime,
23-
formatPeriod,
24-
} from "@dub/utils/src/functions/datetime";
21+
} from "@dub/utils";
22+
import { formatPeriod } from "@dub/utils/src/functions/datetime";
2523
import Link from "next/link";
2624
import { useParams } from "next/navigation";
2725
import { Dispatch, Fragment, SetStateAction, useMemo, useState } from "react";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const formatDateTimeSmart = (
2+
datetime: Date | string,
3+
options?: Intl.DateTimeFormatOptions,
4+
) => {
5+
const date = new Date(datetime);
6+
const now = new Date();
7+
8+
return new Date(datetime).toLocaleDateString("en-US", {
9+
month: "short",
10+
day: "numeric",
11+
// if date is in previous year, show year
12+
// else, hide year, show time
13+
...(date.getUTCFullYear() !== now.getUTCFullYear()
14+
? { year: "numeric" }
15+
: {
16+
hour: "numeric",
17+
minute: "numeric",
18+
hour12: true,
19+
}),
20+
...options,
21+
});
22+
};

packages/utils/src/functions/datetime/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from "./billing-utils";
22
export * from "./format-date";
33
export * from "./format-datetime";
4+
export * from "./format-datetime-smart";
45
export * from "./format-period";
56
export * from "./get-datetime-local";
67
export * from "./get-days-difference";

0 commit comments

Comments
 (0)