index.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 = require("../../../../index.js");
  8. var _index2 = _interopRequireDefault(require("../../../../_lib/isSameUTCWeek/index.js"));
  9. var accusativeWeekdays = ['нядзелю', 'панядзелак', 'аўторак', 'сераду', 'чацьвер', 'пятніцу', 'суботу'];
  10. function lastWeek(day) {
  11. var weekday = accusativeWeekdays[day];
  12. switch (day) {
  13. case 0:
  14. case 3:
  15. case 5:
  16. case 6:
  17. return "'у мінулую " + weekday + " а' p";
  18. case 1:
  19. case 2:
  20. case 4:
  21. return "'у мінулы " + weekday + " а' p";
  22. }
  23. }
  24. function thisWeek(day) {
  25. var weekday = accusativeWeekdays[day];
  26. return "'у " + weekday + " а' p";
  27. }
  28. function nextWeek(day) {
  29. var weekday = accusativeWeekdays[day];
  30. switch (day) {
  31. case 0:
  32. case 3:
  33. case 5:
  34. case 6:
  35. return "'у наступную " + weekday + " а' p";
  36. case 1:
  37. case 2:
  38. case 4:
  39. return "'у наступны " + weekday + " а' p";
  40. }
  41. }
  42. var lastWeekFormat = function lastWeekFormat(dirtyDate, baseDate, options) {
  43. var date = (0, _index.toDate)(dirtyDate);
  44. var day = date.getUTCDay();
  45. if ((0, _index2.default)(date, baseDate, options)) {
  46. return thisWeek(day);
  47. } else {
  48. return lastWeek(day);
  49. }
  50. };
  51. var nextWeekFormat = function nextWeekFormat(dirtyDate, baseDate, options) {
  52. var date = (0, _index.toDate)(dirtyDate);
  53. var day = date.getUTCDay();
  54. if ((0, _index2.default)(date, baseDate, options)) {
  55. return thisWeek(day);
  56. } else {
  57. return nextWeek(day);
  58. }
  59. };
  60. var formatRelativeLocale = {
  61. lastWeek: lastWeekFormat,
  62. yesterday: "'учора а' p",
  63. today: "'сёньня а' p",
  64. tomorrow: "'заўтра а' p",
  65. nextWeek: nextWeekFormat,
  66. other: 'P'
  67. };
  68. var formatRelative = function formatRelative(token, date, baseDate, options) {
  69. var format = formatRelativeLocale[token];
  70. if (typeof format === 'function') {
  71. return format(date, baseDate, options);
  72. }
  73. return format;
  74. };
  75. var _default = formatRelative;
  76. exports.default = _default;
  77. module.exports = exports.default;