diff --git a/src/lib/datetime.ts b/src/lib/datetime.ts index 35db356..dd8e126 100644 --- a/src/lib/datetime.ts +++ b/src/lib/datetime.ts @@ -108,6 +108,16 @@ export const pprintDateRange = (d1: string | Date | Dayjs, d2: string | Date | D } } +/** + * Format a datetime for Excel export. + * The date is formatted as "YYYY-MM-DD HH:mm:ss". + * @param date - The date string to format. + * @return {string} The formatted date. + */ +export function formatDateForExcel(date: string | Date | Dayjs): string { + return dayjs(date).format('YYYY-MM-DD HH:mm:ss'); +} + /** * Format the duration between two dates. * The Duration is precise to the minute. diff --git a/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx b/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx index cc898a9..76f4e39 100644 --- a/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx +++ b/src/pages/events/e/:eventId/EventLists/Search/DownloadDataModal.tsx @@ -12,6 +12,7 @@ import {onlyUnique} from "@/lib/util.ts"; import {CSV_CHARSETS, downloadCsv} from "@/lib/csv.ts"; import {showSuccessNotification} from "@/components/util.tsx"; import {PocketBaseErrorAlert} from "@/lib/pocketbase.tsx"; +import {formatDateForExcel} from "@/lib/datetime.ts"; type FormValues = { questionSchemaFields: string[] @@ -121,7 +122,7 @@ export default function DownloadDataModal({opened, onClose, lists, event, query} const statusData = e.entryStatusData || {} return [ ...(showDebug ? [e.user, e.id] : []), - e.expand?.user.username ?? "N/A", e.created, e.listName, e.slotStartDate, e.slotEndDate, + e.expand?.user.username ?? "N/A", formatDateForExcel(e.created), e.listName, formatDateForExcel(e.slotStartDate), formatDateForExcel(e.slotEndDate), ...questionSchema.fields.map(f => questionData[f.id]?.value?.toString() ?? "N/A").map(escapeSeparator), ...statusSchema.fields.map(f => statusData[f.id]?.value?.toString() ?? "N/A").map(escapeSeparator) ]