index.js 897 B

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = endOfYesterday;
  6. /**
  7. * @name endOfYesterday
  8. * @category Day Helpers
  9. * @summary Return the end of yesterday.
  10. * @pure false
  11. *
  12. * @description
  13. * Return the end of yesterday.
  14. *
  15. * > ⚠️ Please note that this function is not present in the FP submodule as
  16. * > it uses `new Date()` internally hence impure and can't be safely curried.
  17. *
  18. * @returns {Date} the end of yesterday
  19. *
  20. * @example
  21. * // If today is 6 October 2014:
  22. * const result = endOfYesterday()
  23. * //=> Sun Oct 5 2014 23:59:59.999
  24. */
  25. function endOfYesterday() {
  26. var now = new Date();
  27. var year = now.getFullYear();
  28. var month = now.getMonth();
  29. var day = now.getDate();
  30. var date = new Date(0);
  31. date.setFullYear(year, month, day - 1);
  32. date.setHours(23, 59, 59, 999);
  33. return date;
  34. }
  35. module.exports = exports.default;