Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #434 from davidradl/git427
Browse files Browse the repository at this point in the history
Git427 fix date formatting
  • Loading branch information
davidradl committed Apr 29, 2022
2 parents a7f1bbb + 9740662 commit 3c17d05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function DateTimePicker(props) {
placeholder={getDateFormatPlaceHolder()}
labelText={props.dateLabel}
id={props.dateLabel}
value={instancesContext.asOfDate}
value={instancesContext.asOfFormattedDate}
invalid={instancesContext.invalidDate}
invalidText={"Invalid Dates are not accepted"}
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ const InstancesContextProvider = (props) => {
*/
const [asOfDate, setAsOfDate] = useState();

const [asOfFormattedDate, setAsOfFormattedDate] = useState();

/*
* As of date time - the date and time as a date object.
*/
Expand Down Expand Up @@ -179,23 +181,36 @@ const InstancesContextProvider = (props) => {
if (isValid(validatedDateTime)) {
setInvalidTime(false);
setAsOfDateTime(validatedDateTime);
setAsOfFormattedDate(getFormattedDate(validatedDateTime));
} else {
setInvalidTime(true);
setAsOfDateTime(asOfDate);
setAsOfFormattedDate(getFormattedDate(asOfDate));
}
} else {
setInvalidTime(true);
setAsOfDateTime(asOfDate);
setAsOfFormattedDate(getFormattedDate(asOfDate));
}
}
}
} else {
setAsOfDateTime(undefined);
// no point in allowing time to be updated if there is no date
setIsTimeDisabled(true);
setAsOfFormattedDate(undefined);
}
}, [asOfTimeStr, asOfDate]);

const getFormattedDate = (date) => {
// the value needs to be the date string using the date-fns format
let formattedDate = undefined;
if (date != undefined) {
formattedDate = format(date, "MM/dd/Y");
}
return formattedDate;
};

useEffect(() => {
// the clear the context if the date time has changed then existing content should be thrown
clear()
Expand Down Expand Up @@ -1536,7 +1551,8 @@ const InstancesContextProvider = (props) => {
invalidDate,
isTimeDisabled,
useHistoricalQuery,
asOfDate,
asOfDate, // TODO can we remove this and key off the formatted date?
asOfFormattedDate, // needed for the widget
onHistoricalQueryChange,
setGuidToGenId,
setFocus,
Expand Down

0 comments on commit 3c17d05

Please sign in to comment.