("");
const [liveRegionText, setLiveRegionText] = useLiveRegionText("");
+ const [timeBeganFillingForm, setTimeBeganFillingForm] = useState(now());
const postFormData = usePOST(submitEndpoint);
@@ -55,6 +57,7 @@ export const Form = ({ children, ariaLabelledBy, submitEndpoint, successMessage
setLiveRegionText("submitting");
const formData = extractFormData(form);
+ formData.timeToFillForm = `${now() - timeBeganFillingForm} milliseconds`;
postFormData(formData, (ok, _, error) => {
setSubmitting(false);
@@ -68,7 +71,7 @@ export const Form = ({ children, ariaLabelledBy, submitEndpoint, successMessage
}
});
}
- }, [onSubmitObservable, setLiveRegionText, postFormData, onClearObservable]);
+ }, [onSubmitObservable, setLiveRegionText, postFormData, onClearObservable, timeBeganFillingForm]);
return (
{showSuccessMessage &&
diff --git a/src/utilities/date-utilities.test.ts b/src/utilities/date-utilities.test.ts
new file mode 100644
index 0000000..fdfd52b
--- /dev/null
+++ b/src/utilities/date-utilities.test.ts
@@ -0,0 +1,12 @@
+import { now } from "./date-utilities";
+
+describe("date utilities", () => {
+ test("now returns current time in milliseconds since the epoch", () => {
+ const timeFromDate = Date.now();
+ const time = now();
+ const fiveSeconds = 5000;
+
+ expect(time).toBeGreaterThanOrEqual(timeFromDate);
+ expect(time).toBeLessThanOrEqual(timeFromDate + fiveSeconds);
+ });
+});
diff --git a/src/utilities/date-utilities.ts b/src/utilities/date-utilities.ts
new file mode 100644
index 0000000..dee6720
--- /dev/null
+++ b/src/utilities/date-utilities.ts
@@ -0,0 +1 @@
+export const now = (): number => Date.now();