DayParser.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
  2. import _createClass from "@babel/runtime/helpers/esm/createClass";
  3. import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
  4. import _inherits from "@babel/runtime/helpers/esm/inherits";
  5. import _createSuper from "@babel/runtime/helpers/esm/createSuper";
  6. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  7. import { Parser } from "../Parser.js";
  8. import setUTCDay from "../../../_lib/setUTCDay/index.js"; // Day of week
  9. export var DayParser = /*#__PURE__*/function (_Parser) {
  10. _inherits(DayParser, _Parser);
  11. var _super = _createSuper(DayParser);
  12. function DayParser() {
  13. var _this;
  14. _classCallCheck(this, DayParser);
  15. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  16. args[_key] = arguments[_key];
  17. }
  18. _this = _super.call.apply(_super, [this].concat(args));
  19. _defineProperty(_assertThisInitialized(_this), "priority", 90);
  20. _defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['D', 'i', 'e', 'c', 't', 'T']);
  21. return _this;
  22. }
  23. _createClass(DayParser, [{
  24. key: "parse",
  25. value: function parse(dateString, token, match) {
  26. switch (token) {
  27. // Tue
  28. case 'E':
  29. case 'EE':
  30. case 'EEE':
  31. return match.day(dateString, {
  32. width: 'abbreviated',
  33. context: 'formatting'
  34. }) || match.day(dateString, {
  35. width: 'short',
  36. context: 'formatting'
  37. }) || match.day(dateString, {
  38. width: 'narrow',
  39. context: 'formatting'
  40. });
  41. // T
  42. case 'EEEEE':
  43. return match.day(dateString, {
  44. width: 'narrow',
  45. context: 'formatting'
  46. });
  47. // Tu
  48. case 'EEEEEE':
  49. return match.day(dateString, {
  50. width: 'short',
  51. context: 'formatting'
  52. }) || match.day(dateString, {
  53. width: 'narrow',
  54. context: 'formatting'
  55. });
  56. // Tuesday
  57. case 'EEEE':
  58. default:
  59. return match.day(dateString, {
  60. width: 'wide',
  61. context: 'formatting'
  62. }) || match.day(dateString, {
  63. width: 'abbreviated',
  64. context: 'formatting'
  65. }) || match.day(dateString, {
  66. width: 'short',
  67. context: 'formatting'
  68. }) || match.day(dateString, {
  69. width: 'narrow',
  70. context: 'formatting'
  71. });
  72. }
  73. }
  74. }, {
  75. key: "validate",
  76. value: function validate(_date, value) {
  77. return value >= 0 && value <= 6;
  78. }
  79. }, {
  80. key: "set",
  81. value: function set(date, _flags, value, options) {
  82. date = setUTCDay(date, value, options);
  83. date.setUTCHours(0, 0, 0, 0);
  84. return date;
  85. }
  86. }]);
  87. return DayParser;
  88. }(Parser);