0.1.0 β’ Published 6 years ago
isdatevalid v0.1.0
π π isDateValid
Simple utility function to validate that the input is actually a real date
yarn add isdatevalidUsage
Given a year, month and day (as either strings or numbers) return true/false if the given values are valid. Invalid dates are the 29th Feb in a non-leap-year or the 45th January for example.
import { isDateValid } from 'isdatevalid'
/**
* parameters
* isDateValid(year, month, day)
*
* parameter types
* isDateValid(year: number | string, month: number | string, day: number | string): boolean
*/
// π valid
isDateValid(2016, 02, 29) // => true
// 2016 is a leap-year so it is possible to have 29th Feb
isDateValid(2016, 02, 1) // => true
// π invalid
isDateValid(2019, 02, 29) // => false
// 2019 is not a leap-year so it is not possible to have 29th Feb
isDateValid(2019, 45, 29) // => falseThanks to @ivoreis for drastically simplifying my previous efforts and basically writing this entire function on my behalf
Made by ZΞNDΞR β‘
0.1.0
6 years ago