(monthNumber, year)
| 9 | import { isLeapYear } from '../Maths/LeapYear' |
| 10 | |
| 11 | const getMonthDays = (monthNumber, year) => { |
| 12 | const the31DaysMonths = [1, 3, 5, 7, 8, 10, 12] |
| 13 | const the30DaysMonths = [4, 6, 9, 11] |
| 14 | |
| 15 | if ( |
| 16 | !the31DaysMonths.includes(monthNumber) && |
| 17 | !the30DaysMonths.includes(monthNumber) && |
| 18 | monthNumber !== 2 |
| 19 | ) { |
| 20 | throw new TypeError('Invalid Month Number.') |
| 21 | } |
| 22 | |
| 23 | if (the31DaysMonths.includes(monthNumber)) { |
| 24 | return 31 |
| 25 | } |
| 26 | |
| 27 | if (the30DaysMonths.includes(monthNumber)) { |
| 28 | return 30 |
| 29 | } |
| 30 | |
| 31 | if (isLeapYear(year)) { |
| 32 | return 29 |
| 33 | } |
| 34 | |
| 35 | return 28 |
| 36 | } |
| 37 | |
| 38 | export { getMonthDays } |
no test coverage detected