Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jminutaglio authored Apr 19, 2023
1 parent 744f9d7 commit 4704922
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions function-source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ exports.horoscopeAPIprod = async (req, res) => {
return;
}

const parsedDate = Date.parse(date); // parse the input date into milliseconds since Unix epoch

if (isNaN(parsedDate)) { // check if the parsed date is NaN
console.info("Invalid date input -> ", date); // log an error message if the date is invalid
} else { // check if the parsed date is different from the formatted date
const formattedDate = new Date(parsedDate).toLocaleDateString("en-US", { // create a new Date object with the parsed date and format it to "mm-dd-yyyy" format
month: "2-digit",
day: "2-digit",
year: "numeric",
}).replace(/\//g, "-"); // replace all occurrences of "/" with "-" to get "mm-dd-yyyy" format
if (formattedDate != date ) {
console.info("Date input converted from -> ", date, ' to ->', formattedDate); // log a message indicating that the input date was converted
date = formattedDate; // update the date variable with the formatted date
}
}

if (dateRegex.test(date)) {
//date string was in the valid format

Expand Down

0 comments on commit 4704922

Please sign in to comment.