getYearDay.js 649 B

12345678910111213141516171819202122232425
  1. var staticDayTime = require('./staticDayTime')
  2. var staticStrFirst = require('./staticStrFirst')
  3. var helperGetYMDTime = require('./helperGetYMDTime')
  4. var getWhatYear = require('./getWhatYear')
  5. var toStringDate = require('./toStringDate')
  6. var isValidDate = require('./isValidDate')
  7. /**
  8. * 返回某个年份的第几天
  9. *
  10. * @param {Date} date 日期或数字
  11. * @return {Number}
  12. */
  13. function getYearDay (date) {
  14. date = toStringDate(date)
  15. if (isValidDate(date)) {
  16. return Math.floor((helperGetYMDTime(date) - helperGetYMDTime(getWhatYear(date, 0, staticStrFirst))) / staticDayTime) + 1
  17. }
  18. return NaN
  19. }
  20. module.exports = getYearDay