From 3118bd64474771dcf12a4f459be3ee1f864d505e Mon Sep 17 00:00:00 2001 From: Bruce Schultz Date: Mon, 23 Sep 2024 14:46:26 +0200 Subject: [PATCH] fix(timestamp): only parse timestamp fields if they haven't been already --- utils/format-data-row.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/utils/format-data-row.ts b/utils/format-data-row.ts index 73ccb1b..7b1b913 100644 --- a/utils/format-data-row.ts +++ b/utils/format-data-row.ts @@ -31,19 +31,23 @@ function parseUnixTimestamp( keysToModify.forEach((key) => { if (key in dataRow) { const timestamp = dataRow[key]; - let date: Date; - if (isUnixTimestamp(timestamp)) { - // If a unix epoch is returned - date = new Date(timestamp * 1000); - } else { - // If a UTC T/Z timestamp returned - date = new Date(timestamp); + if (typeof timestamp === "string") { + // If not a string then already parsed as object + let date: Date; + console.log(timestamp); + if (isUnixTimestamp(timestamp)) { + // If a unix epoch is returned + date = new Date(timestamp * 1000); + } else { + // If a UTC T/Z timestamp returned + date = new Date(timestamp); + } + dataRow[key] = { + short: formatDate(date), + long: date.toUTCString(), + date: date, + }; } - dataRow[key] = { - short: formatDate(date), - long: date.toUTCString(), - date: date, - }; } }); return dataRow;