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; }