index.js 556 B

123456789101112131415161718192021222324
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Quarter Helpers
  4. * @summary Get the year quarter of the given date.
  5. *
  6. * @description
  7. * Get the year quarter of the given date.
  8. *
  9. * @param {Date|String|Number} date - the given date
  10. * @returns {Number} the quarter
  11. *
  12. * @example
  13. * // Which quarter is 2 July 2014?
  14. * var result = getQuarter(new Date(2014, 6, 2))
  15. * //=> 3
  16. */
  17. function getQuarter (dirtyDate) {
  18. var date = parse(dirtyDate)
  19. var quarter = Math.floor(date.getMonth() / 3) + 1
  20. return quarter
  21. }
  22. module.exports = getQuarter