totalDaysInMonth.js 662 B

12345678910111213141516171819202122232425
  1. var isDate = require('../lang/isDate');
  2. var isLeapYear = require('./isLeapYear');
  3. var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  4. /**
  5. * returns the total amount of days in the month (considering leap years)
  6. */
  7. function totalDaysInMonth(fullYear, monthIndex){
  8. if (isDate(fullYear)) {
  9. var date = fullYear;
  10. year = date.getFullYear();
  11. monthIndex = date.getMonth();
  12. }
  13. if (monthIndex === 1 && isLeapYear(fullYear)) {
  14. return 29;
  15. } else {
  16. return DAYS_IN_MONTH[monthIndex];
  17. }
  18. }
  19. module.exports = totalDaysInMonth;