ISODayParser.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.ISODayParser = 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/setUTCISODay/index.js"));
  16. // ISO day of week
  17. var ISODayParser = /*#__PURE__*/function (_Parser) {
  18. (0, _inherits2.default)(ISODayParser, _Parser);
  19. var _super = (0, _createSuper2.default)(ISODayParser);
  20. function ISODayParser() {
  21. var _this;
  22. (0, _classCallCheck2.default)(this, ISODayParser);
  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', 'Y', 'u', 'q', 'Q', 'M', 'L', 'w', 'd', 'D', 'E', 'e', 'c', 't', 'T']);
  29. return _this;
  30. }
  31. (0, _createClass2.default)(ISODayParser, [{
  32. key: "parse",
  33. value: function parse(dateString, token, match) {
  34. var valueCallback = function valueCallback(value) {
  35. if (value === 0) {
  36. return 7;
  37. }
  38. return value;
  39. };
  40. switch (token) {
  41. // 2
  42. case 'i':
  43. case 'ii':
  44. // 02
  45. return (0, _utils.parseNDigits)(token.length, dateString);
  46. // 2nd
  47. case 'io':
  48. return match.ordinalNumber(dateString, {
  49. unit: 'day'
  50. });
  51. // Tue
  52. case 'iii':
  53. return (0, _utils.mapValue)(match.day(dateString, {
  54. width: 'abbreviated',
  55. context: 'formatting'
  56. }) || match.day(dateString, {
  57. width: 'short',
  58. context: 'formatting'
  59. }) || match.day(dateString, {
  60. width: 'narrow',
  61. context: 'formatting'
  62. }), valueCallback);
  63. // T
  64. case 'iiiii':
  65. return (0, _utils.mapValue)(match.day(dateString, {
  66. width: 'narrow',
  67. context: 'formatting'
  68. }), valueCallback);
  69. // Tu
  70. case 'iiiiii':
  71. return (0, _utils.mapValue)(match.day(dateString, {
  72. width: 'short',
  73. context: 'formatting'
  74. }) || match.day(dateString, {
  75. width: 'narrow',
  76. context: 'formatting'
  77. }), valueCallback);
  78. // Tuesday
  79. case 'iiii':
  80. default:
  81. return (0, _utils.mapValue)(match.day(dateString, {
  82. width: 'wide',
  83. context: 'formatting'
  84. }) || match.day(dateString, {
  85. width: 'abbreviated',
  86. context: 'formatting'
  87. }) || match.day(dateString, {
  88. width: 'short',
  89. context: 'formatting'
  90. }) || match.day(dateString, {
  91. width: 'narrow',
  92. context: 'formatting'
  93. }), valueCallback);
  94. }
  95. }
  96. }, {
  97. key: "validate",
  98. value: function validate(_date, value) {
  99. return value >= 1 && value <= 7;
  100. }
  101. }, {
  102. key: "set",
  103. value: function set(date, _flags, value) {
  104. date = (0, _index.default)(date, value);
  105. date.setUTCHours(0, 0, 0, 0);
  106. return date;
  107. }
  108. }]);
  109. return ISODayParser;
  110. }(_Parser2.Parser);
  111. exports.ISODayParser = ISODayParser;