StandAloneLocalDayParser.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 { mapValue, parseNDigits } from "../utils.js";
  9. import setUTCDay from "../../../_lib/setUTCDay/index.js"; // Stand-alone local day of week
  10. export var StandAloneLocalDayParser = /*#__PURE__*/function (_Parser) {
  11. _inherits(StandAloneLocalDayParser, _Parser);
  12. var _super = _createSuper(StandAloneLocalDayParser);
  13. function StandAloneLocalDayParser() {
  14. var _this;
  15. _classCallCheck(this, StandAloneLocalDayParser);
  16. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  17. args[_key] = arguments[_key];
  18. }
  19. _this = _super.call.apply(_super, [this].concat(args));
  20. _defineProperty(_assertThisInitialized(_this), "priority", 90);
  21. _defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['y', 'R', 'u', 'q', 'Q', 'M', 'L', 'I', 'd', 'D', 'E', 'i', 'e', 't', 'T']);
  22. return _this;
  23. }
  24. _createClass(StandAloneLocalDayParser, [{
  25. key: "parse",
  26. value: function parse(dateString, token, match, options) {
  27. var valueCallback = function valueCallback(value) {
  28. var wholeWeekDays = Math.floor((value - 1) / 7) * 7;
  29. return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
  30. };
  31. switch (token) {
  32. // 3
  33. case 'c':
  34. case 'cc':
  35. // 03
  36. return mapValue(parseNDigits(token.length, dateString), valueCallback);
  37. // 3rd
  38. case 'co':
  39. return mapValue(match.ordinalNumber(dateString, {
  40. unit: 'day'
  41. }), valueCallback);
  42. // Tue
  43. case 'ccc':
  44. return match.day(dateString, {
  45. width: 'abbreviated',
  46. context: 'standalone'
  47. }) || match.day(dateString, {
  48. width: 'short',
  49. context: 'standalone'
  50. }) || match.day(dateString, {
  51. width: 'narrow',
  52. context: 'standalone'
  53. });
  54. // T
  55. case 'ccccc':
  56. return match.day(dateString, {
  57. width: 'narrow',
  58. context: 'standalone'
  59. });
  60. // Tu
  61. case 'cccccc':
  62. return match.day(dateString, {
  63. width: 'short',
  64. context: 'standalone'
  65. }) || match.day(dateString, {
  66. width: 'narrow',
  67. context: 'standalone'
  68. });
  69. // Tuesday
  70. case 'cccc':
  71. default:
  72. return match.day(dateString, {
  73. width: 'wide',
  74. context: 'standalone'
  75. }) || match.day(dateString, {
  76. width: 'abbreviated',
  77. context: 'standalone'
  78. }) || match.day(dateString, {
  79. width: 'short',
  80. context: 'standalone'
  81. }) || match.day(dateString, {
  82. width: 'narrow',
  83. context: 'standalone'
  84. });
  85. }
  86. }
  87. }, {
  88. key: "validate",
  89. value: function validate(_date, value) {
  90. return value >= 0 && value <= 6;
  91. }
  92. }, {
  93. key: "set",
  94. value: function set(date, _flags, value, options) {
  95. date = setUTCDay(date, value, options);
  96. date.setUTCHours(0, 0, 0, 0);
  97. return date;
  98. }
  99. }]);
  100. return StandAloneLocalDayParser;
  101. }(Parser);