AMPMMidnightParser.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.AMPMMidnightParser = 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 AMPMMidnightParser = /*#__PURE__*/function (_Parser) {
  16. (0, _inherits2.default)(AMPMMidnightParser, _Parser);
  17. var _super = (0, _createSuper2.default)(AMPMMidnightParser);
  18. function AMPMMidnightParser() {
  19. var _this;
  20. (0, _classCallCheck2.default)(this, AMPMMidnightParser);
  21. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  22. args[_key] = arguments[_key];
  23. }
  24. _this = _super.call.apply(_super, [this].concat(args));
  25. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "priority", 80);
  26. (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "incompatibleTokens", ['a', 'B', 'H', 'k', 't', 'T']);
  27. return _this;
  28. }
  29. (0, _createClass2.default)(AMPMMidnightParser, [{
  30. key: "parse",
  31. value: function parse(dateString, token, match) {
  32. switch (token) {
  33. case 'b':
  34. case 'bb':
  35. case 'bbb':
  36. return match.dayPeriod(dateString, {
  37. width: 'abbreviated',
  38. context: 'formatting'
  39. }) || match.dayPeriod(dateString, {
  40. width: 'narrow',
  41. context: 'formatting'
  42. });
  43. case 'bbbbb':
  44. return match.dayPeriod(dateString, {
  45. width: 'narrow',
  46. context: 'formatting'
  47. });
  48. case 'bbbb':
  49. default:
  50. return match.dayPeriod(dateString, {
  51. width: 'wide',
  52. context: 'formatting'
  53. }) || match.dayPeriod(dateString, {
  54. width: 'abbreviated',
  55. context: 'formatting'
  56. }) || match.dayPeriod(dateString, {
  57. width: 'narrow',
  58. context: 'formatting'
  59. });
  60. }
  61. }
  62. }, {
  63. key: "set",
  64. value: function set(date, _flags, value) {
  65. date.setUTCHours((0, _utils.dayPeriodEnumToHours)(value), 0, 0, 0);
  66. return date;
  67. }
  68. }]);
  69. return AMPMMidnightParser;
  70. }(_Parser2.Parser);
  71. exports.AMPMMidnightParser = AMPMMidnightParser;