startOfYesterday.js 653 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.startOfYesterday = startOfYesterday; /**
  3. * @name startOfYesterday
  4. * @category Day Helpers
  5. * @summary Return the start of yesterday.
  6. * @pure false
  7. *
  8. * @description
  9. * Return the start of yesterday.
  10. *
  11. * @returns The start of yesterday
  12. *
  13. * @example
  14. * // If today is 6 October 2014:
  15. * const result = startOfYesterday()
  16. * //=> Sun Oct 5 2014 00:00:00
  17. */
  18. function startOfYesterday() {
  19. const now = new Date();
  20. const year = now.getFullYear();
  21. const month = now.getMonth();
  22. const day = now.getDate();
  23. const date = new Date(0);
  24. date.setFullYear(year, month, day - 1);
  25. date.setHours(0, 0, 0, 0);
  26. return date;
  27. }