Skip to content

Commit

Permalink
invalid date catch in patternfly date adapter (#224)
Browse files Browse the repository at this point in the history
* invalid date catch in patternfly date adapter

* added null end_date check when calculating retirement date

* fixed date instance check
  • Loading branch information
sdstolworthy authored Jun 30, 2020
1 parent 710ad5f commit 309d4f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common/patternfly_date_adapter.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { format as formatDate, parse as parseDate } from 'date-fns';
import { format as formatDate, parse as parseDate, isValid } from 'date-fns';
export const getFormattedDate = (inputDate: Date | string = ''): string => {
// Dates must be formatted YYYY-MM-DD for patternfly date picker.
// They are coming back inconsistently from the backend,
// so this function checks to see if the date needs to be formatted,
// then formats the date appropriately
if (!inputDate) {
if (!inputDate || (inputDate instanceof Date && !isValid(inputDate))) {
return;
}
if (inputDate instanceof Date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export function EngagementStartEndDateFormField(
] as number) ?? 0;

const getRetirementDate = (): string => {
if (
!props.engagement.end_date ||
!(props.engagement?.end_date instanceof Date)
) {
return undefined;
}
if (props.engagement?.archive_date || retirementDateChanged) {
return getFormattedDate(props.engagement?.archive_date);
} else if (props.engagement?.end_date) {
Expand Down

0 comments on commit 309d4f4

Please sign in to comment.