Skip to content

Commit

Permalink
fix(timestamp): only parse timestamp fields if they haven't been already
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Sep 23, 2024
1 parent 9612876 commit 3118bd6
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions utils/format-data-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3118bd6

Please sign in to comment.