Skip to content

Commit

Permalink
Merge pull request #954 from cityofaustin/2439_date_bug
Browse files Browse the repository at this point in the history
Fix invalid date bug by passing a fallback value
  • Loading branch information
mateoclarke authored Dec 2, 2020
2 parents cd2471c + 8db9892 commit a28d492
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions atd-vze/src/Components/GridDateRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ const GridDateRange = ({ setDateRangeFilter, initStartDate, initEndDate, uniqueK
/**
* Returns a date in a valid SQL format.
* @param {string} date - The string to be transformed
* @param {string} fallbackValue - The value to use if the formattedDate is invalid
* @returns {string}
*/
const formatDate = date => moment(date).format("YYYY-MM-DD");
const formatDate = (date, fallbackValue) => {
let formattedDate = moment(date).format("YYYY-MM-DD");

if (formattedDate === "Invalid date") {
formattedDate = moment(fallbackValue).format("YYYY-MM-DD");
}
return formattedDate;
};

/**
* Returns today
Expand All @@ -74,8 +82,8 @@ const GridDateRange = ({ setDateRangeFilter, initStartDate, initEndDate, uniqueK
// Set date range filter in GridTable if startDate or endDate changes
useEffect(() => {
setDateRangeFilter({
startDate: formatDate(startDate),
endDate: formatDate(endDate),
startDate: formatDate(startDate, initStartDate),
endDate: formatDate(endDate, initEndDate),
});
}, [startDate, endDate, setDateRangeFilter]);

Expand Down

0 comments on commit a28d492

Please sign in to comment.