Skip to content

Commit

Permalink
fix(utils): fix broken date parsing
Browse files Browse the repository at this point in the history
Published date would default to today
  • Loading branch information
Darth-Knoppix committed Jun 7, 2020
1 parent a5e7105 commit f30466a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ export function cleanDate(rawDate) {
return rawDate;
}
if (typeof rawDate === "string") {
const parsedDate = Date.parse(rawDate);
const dateParts = rawDate.split(/\D+/);

if (isNaN(parsedDate)) return undefined;

return new Date();
return new Date(
Date.UTC(
dateParts[0],
--dateParts[1],
dateParts[2],
dateParts[3],
dateParts[4],
dateParts[5],
dateParts[6]
)
);
}

return undefined;
Expand Down

0 comments on commit f30466a

Please sign in to comment.