Skip to content

Commit

Permalink
feat: Capture epoch time in DateInput
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jan 19, 2024
1 parent f791959 commit b95b60b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ test("recovers previously submitted date when clicking the back button even if a
expect(handleSubmit).toHaveBeenCalledWith({
data: {
[dataField]: "2010-05-22",
[dataField + ".epoch"]: 1274486400,
},
});
});
Expand Down
13 changes: 11 additions & 2 deletions editor.planx.uk/src/@planx/components/DateInput/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import InputRow from "ui/shared/InputRow";
import { object } from "yup";

import { DESCRIPTION_TEXT, ERROR_MESSAGE } from "../shared/constants";
import { getPreviouslySubmittedData, makeData } from "../shared/utils";
import { getPreviouslySubmittedData } from "../shared/utils";

export type Props = PublicProps<DateInput>;

Expand All @@ -22,7 +22,16 @@ const DateInputPublic: React.FC<Props> = (props) => {
date: getPreviouslySubmittedData(props) ?? "",
},
onSubmit: (values) => {
props.handleSubmit?.(makeData(props, values.date));
props.handleSubmit?.({
data: props.fn
? {
// Capture user data as ISO 8601
[props.fn]: values.date,
// Capture user data as epoch time (for use in calculate component)
[props.fn + ".epoch"]: new Date(values.date).valueOf() / 1000,
}
: undefined
});
},
validateOnBlur: false,
validateOnChange: false,
Expand Down

0 comments on commit b95b60b

Please sign in to comment.