LocalDayParser.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.LocalDayParser = void 0;
  7. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
  8. var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
  9. var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
  10. var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
  11. var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));
  12. var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  13. var _Parser2 = require("../Parser.js");
  14. var _utils = require("../utils.js");
  15. var _index = _interopRequireDefault(require("../../../_lib/setUTCDay/index.js"));
  16. // Local day of week
  17. var LocalDayParser = /*#__PURE__*/function (_Parser) {
  18. (0, _inherits2.default)(LocalDayParser, _Parser);
  19. var _super = (0, _createSuper2.default)(LocalDayParser);
  20. function LocalDayParser() {
  21. var _this;
  22. (0, _classCallCheck2.default)(this, LocalDayParser);
  23. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  24. args[_key] = arguments[_key];
  25. }
  26. _this = _super.call.apply(_super, [this].concat(args));
  27. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "priority", 90);
  28. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "incompatibleTokens", ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'c', 't', 'T']);
  29. return _this;
  30. }
  31. (0, _createClass2.default)(LocalDayParser, [{
  32. key: "parse",
  33. value: function parse(dateString, token, match, options) {
  34. var valueCallback = function valueCallback(value) {
  35. var wholeWeekDays = Math.floor((value - 1) / 7) * 7;
  36. return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
  37. };
  38. switch (token) {
  39. // 3
  40. case 'e':
  41. case 'ee':
  42. // 03
  43. return (0, _utils.mapValue)((0, _utils.parseNDigits)(token.length, dateString), valueCallback);
  44. // 3rd
  45. case 'eo':
  46. return (0, _utils.mapValue)(match.ordinalNumber(dateString, {
  47. unit: 'day'
  48. }), valueCallback);
  49. // Tue
  50. case 'eee':
  51. return match.day(dateString, {
  52. width: 'abbreviated',
  53. context: 'formatting'
  54. }) || match.day(dateString, {
  55. width: 'short',
  56. context: 'formatting'
  57. }) || match.day(dateString, {
  58. width: 'narrow',
  59. context: 'formatting'
  60. });
  61. // T
  62. case 'eeeee':
  63. return match.day(dateString, {
  64. width: 'narrow',
  65. context: 'formatting'
  66. });
  67. // Tu
  68. case 'eeeeee':
  69. return match.day(dateString, {
  70. width: 'short',
  71. context: 'formatting'
  72. }) || match.day(dateString, {
  73. width: 'narrow',
  74. context: 'formatting'
  75. });
  76. // Tuesday
  77. case 'eeee':
  78. default:
  79. return match.day(dateString, {
  80. width: 'wide',
  81. context: 'formatting'
  82. }) || match.day(dateString, {
  83. width: 'abbreviated',
  84. context: 'formatting'
  85. }) || match.day(dateString, {
  86. width: 'short',
  87. context: 'formatting'
  88. }) || match.day(dateString, {
  89. width: 'narrow',
  90. context: 'formatting'
  91. });
  92. }
  93. }
  94. }, {
  95. key: "validate",
  96. value: function validate(_date, value) {
  97. return value >= 0 && value <= 6;
  98. }
  99. }, {
  100. key: "set",
  101. value: function set(date, _flags, value, options) {
  102. date = (0, _index.default)(date, value, options);
  103. date.setUTCHours(0, 0, 0, 0);
  104. return date;
  105. }
  106. }]);
  107. return LocalDayParser;
  108. }(_Parser2.Parser);
  109. exports.LocalDayParser = LocalDayParser;