Checks if the given date is present and it is valid.

Type signature

(date?: unknown) => boolean

Examples

valid(
  new Date(
    "2020-01-31T09:52:31.618Z",
  ),
);
// ⇒ true
Try in REPL
valid(
  new Date("2020-01-42:52:31.618Z"),
);
// ⇒ false
Try in REPL
valid(new Date("test"));
// ⇒ false
Try in REPL
valid(undefined);
// ⇒ false
Try in REPL

Questions

  • How to check if a Date is valid or not?

TypeScript sourceJavaScript source