index.js 781 B

12345678910111213141516171819202122232425262728
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Year Helpers
  4. * @summary Are the given dates in the same year?
  5. *
  6. * @description
  7. * Are the given dates in the same year?
  8. *
  9. * @param {Date|String|Number} dateLeft - the first date to check
  10. * @param {Date|String|Number} dateRight - the second date to check
  11. * @returns {Boolean} the dates are in the same year
  12. *
  13. * @example
  14. * // Are 2 September 2014 and 25 September 2014 in the same year?
  15. * var result = isSameYear(
  16. * new Date(2014, 8, 2),
  17. * new Date(2014, 8, 25)
  18. * )
  19. * //=> true
  20. */
  21. function isSameYear (dirtyDateLeft, dirtyDateRight) {
  22. var dateLeft = parse(dirtyDateLeft)
  23. var dateRight = parse(dirtyDateRight)
  24. return dateLeft.getFullYear() === dateRight.getFullYear()
  25. }
  26. module.exports = isSameYear