fix: date upload in table spit
This commit is contained in:
parent
720ae06d78
commit
1eb206e218
|
|
@ -15,7 +15,7 @@ import {
|
|||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { format } from "date-fns";
|
||||
import { format, parseISO } from "date-fns";
|
||||
import { Link } from "@/components/navigation";
|
||||
import { useTranslations } from "next-intl";
|
||||
import withReactContent from "sweetalert2-react-content";
|
||||
|
|
@ -118,21 +118,43 @@ const useTableColumns = () => {
|
|||
);
|
||||
},
|
||||
},
|
||||
// {
|
||||
// accessorKey: "contentCreatedDate",
|
||||
// header: t("upload-date", { defaultValue: "Upload Date" }),
|
||||
// cell: ({ row }) => {
|
||||
// const createdAt = row.getValue("contentCreatedDate") as
|
||||
// | string
|
||||
// | number
|
||||
// | undefined;
|
||||
// const formattedDate =
|
||||
// createdAt && !isNaN(new Date(createdAt).getTime())
|
||||
// ? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss")
|
||||
// : "-";
|
||||
// return <span className="whitespace-nowrap">{formattedDate}</span>;
|
||||
// },
|
||||
// },
|
||||
{
|
||||
accessorKey: "contentCreatedDate",
|
||||
header: t("upload-date", { defaultValue: "Upload Date" }),
|
||||
cell: ({ row }) => {
|
||||
const createdAt = row.getValue("contentCreatedDate") as
|
||||
| string
|
||||
| number
|
||||
| undefined;
|
||||
const formattedDate =
|
||||
createdAt && !isNaN(new Date(createdAt).getTime())
|
||||
? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss")
|
||||
: "-";
|
||||
const createdAt = row.getValue("contentCreatedDate") as string | null;
|
||||
|
||||
if (!createdAt) return <span>-</span>;
|
||||
|
||||
// parse ISO string dari API (UTC)
|
||||
const date = parseISO(createdAt);
|
||||
|
||||
// geser balik dengan timezoneOffset supaya yang tampil = UTC
|
||||
const utcDate = new Date(
|
||||
date.getTime() + date.getTimezoneOffset() * 60000
|
||||
);
|
||||
|
||||
const formattedDate = format(utcDate, "dd-MM-yyyy HH:mm:ss");
|
||||
|
||||
return <span className="whitespace-nowrap">{formattedDate}</span>;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
id: "actions",
|
||||
accessorKey: "action",
|
||||
|
|
|
|||
Loading…
Reference in New Issue