Skip to content

Instantly share code, notes, and snippets.

@emmiep
Created July 2, 2021 17:49
Show Gist options
  • Save emmiep/80b124115082342a47f48d5cdd65a2d2 to your computer and use it in GitHub Desktop.
Save emmiep/80b124115082342a47f48d5cdd65a2d2 to your computer and use it in GitHub Desktop.

Revisions

  1. emmiep created this gist Jul 2, 2021.
    9 changes: 9 additions & 0 deletions validate.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function validateDate(year, month, day) {
    const date = new Date(year, month, day);

    if (year !== date.getFullYear() || month !== date.getMonth() || day !== date.getDate()) {
    throw new Error('Invalid date');
    }

    return date;
    }