index.js 795 B

1234567891011121314151617181920212223242526272829303132
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Common Helpers
  4. * @summary Return the latest of the given dates.
  5. *
  6. * @description
  7. * Return the latest of the given dates.
  8. *
  9. * @param {...(Date|String|Number)} dates - the dates to compare
  10. * @returns {Date} the latest of the dates
  11. *
  12. * @example
  13. * // Which of these dates is the latest?
  14. * var result = max(
  15. * new Date(1989, 6, 10),
  16. * new Date(1987, 1, 11),
  17. * new Date(1995, 6, 2),
  18. * new Date(1990, 0, 1)
  19. * )
  20. * //=> Sun Jul 02 1995 00:00:00
  21. */
  22. function max () {
  23. var dirtyDates = Array.prototype.slice.call(arguments)
  24. var dates = dirtyDates.map(function (dirtyDate) {
  25. return parse(dirtyDate)
  26. })
  27. var latestTimestamp = Math.max.apply(null, dates)
  28. return new Date(latestTimestamp)
  29. }
  30. module.exports = max