AMPMParser.js 2.7 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.AMPMParser = 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 AMPMParser = /*#__PURE__*/function (_Parser) {
  16. (0, _inherits2.default)(AMPMParser, _Parser);
  17. var _super = (0, _createSuper2.default)(AMPMParser);
  18. function AMPMParser() {
  19. var _this;
  20. (0, _classCallCheck2.default)(this, AMPMParser);
  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", ['b', 'B', 'H', 'k', 't', 'T']);
  27. return _this;
  28. }
  29. (0, _createClass2.default)(AMPMParser, [{
  30. key: "parse",
  31. value: function parse(dateString, token, match) {
  32. switch (token) {
  33. case 'a':
  34. case 'aa':
  35. case 'aaa':
  36. return match.dayPeriod(dateString, {
  37. width: 'abbreviated',
  38. context: 'formatting'
  39. }) || match.dayPeriod(dateString, {
  40. width: 'narrow',
  41. context: 'formatting'
  42. });
  43. case 'aaaaa':
  44. return match.dayPeriod(dateString, {
  45. width: 'narrow',
  46. context: 'formatting'
  47. });
  48. case 'aaaa':
  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 AMPMParser;
  70. }(_Parser2.Parser);
  71. exports.AMPMParser = AMPMParser;