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

Git427 fix date formatting #434

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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