index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _index = _interopRequireDefault(require("../../../../_lib/isSameUTCWeek/index.js"));
  8. function checkWeek(date, baseDate, options) {
  9. var baseFormat = 'eeee p';
  10. if ((0, _index.default)(date, baseDate, options)) {
  11. return baseFormat; // in same week
  12. } else if (date.getTime() > baseDate.getTime()) {
  13. return "'下个'" + baseFormat; // in next week
  14. }
  15. return "'上个'" + baseFormat; // in last week
  16. }
  17. var formatRelativeLocale = {
  18. lastWeek: checkWeek,
  19. // days before yesterday, maybe in this week or last week
  20. yesterday: "'昨天' p",
  21. today: "'今天' p",
  22. tomorrow: "'明天' p",
  23. nextWeek: checkWeek,
  24. // days after tomorrow, maybe in this week or next week
  25. other: 'PP p'
  26. };
  27. var formatRelative = function formatRelative(token, date, baseDate, options) {
  28. var format = formatRelativeLocale[token];
  29. if (typeof format === 'function') {
  30. return format(date, baseDate, options);
  31. }
  32. return format;
  33. };
  34. var _default = formatRelative;
  35. exports.default = _default;
  36. module.exports = exports.default;