isLeapYear.js 514 B

12345678910111213141516171819202122
  1. var isDate = require('./isDate')
  2. var toStringDate = require('./toStringDate')
  3. var helperNewDate = require('./helperNewDate')
  4. /**
  5. * 判断是否闰年
  6. *
  7. * @param {Date} date 日期或数字
  8. * @return {Boolean}
  9. */
  10. function isLeapYear (date) {
  11. var year
  12. var currentDate = date ? toStringDate(date) : helperNewDate()
  13. if (isDate(currentDate)) {
  14. year = currentDate.getFullYear()
  15. return (year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0)
  16. }
  17. return false
  18. }
  19. module.exports = isLeapYear