Develop ultra fast with Prismane 🎉

after

This validator checks if a date is after a given date.

Basic Usage

import { after } from "@prismane/core/validators";

// new Date(Date.now() + 86400000) - Tommorow
console.log(after(new Date(Date.now()), new Date(Date.now() + 86400000))); // Will return null
// new Date(Date.now() - 86400000) - Yesterday
console.log(after(new Date(Date.now() - 86400000), new Date(Date.now()))); // Will return an error`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      date: {
        value: "",
        validators: {
          after: (v: string) =>
            after(new Date(v), new Date(Date.now() - 86400000)),
        },
      },
    },
  });

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v, ""));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <NativeDateField
        placeholder="Enter date: "
        label="Date:"
        {...register("date")}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

Parameters

NameTypeDescription
dateDateThe date that will be validated.
targetDateThe target date.
fieldNamestring / undefinedThe name of the field.