DayPeriodParser.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 { dayPeriodEnumToHours } from "../utils.js"; // in the morning, in the afternoon, in the evening, at night
  9. export var DayPeriodParser = /*#__PURE__*/function (_Parser) {
  10. _inherits(DayPeriodParser, _Parser);
  11. var _super = _createSuper(DayPeriodParser);
  12. function DayPeriodParser() {
  13. var _this;
  14. _classCallCheck(this, DayPeriodParser);
  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", 80);
  20. _defineProperty(_assertThisInitialized(_this), "incompatibleTokens", ['a', 'b', 't', 'T']);
  21. return _this;
  22. }
  23. _createClass(DayPeriodParser, [{
  24. key: "parse",
  25. value: function parse(dateString, token, match) {
  26. switch (token) {
  27. case 'B':
  28. case 'BB':
  29. case 'BBB':
  30. return match.dayPeriod(dateString, {
  31. width: 'abbreviated',
  32. context: 'formatting'
  33. }) || match.dayPeriod(dateString, {
  34. width: 'narrow',
  35. context: 'formatting'
  36. });
  37. case 'BBBBB':
  38. return match.dayPeriod(dateString, {
  39. width: 'narrow',
  40. context: 'formatting'
  41. });
  42. case 'BBBB':
  43. default:
  44. return match.dayPeriod(dateString, {
  45. width: 'wide',
  46. context: 'formatting'
  47. }) || match.dayPeriod(dateString, {
  48. width: 'abbreviated',
  49. context: 'formatting'
  50. }) || match.dayPeriod(dateString, {
  51. width: 'narrow',
  52. context: 'formatting'
  53. });
  54. }
  55. }
  56. }, {
  57. key: "set",
  58. value: function set(date, _flags, value) {
  59. date.setUTCHours(dayPeriodEnumToHours(value), 0, 0, 0);
  60. return date;
  61. }
  62. }]);
  63. return DayPeriodParser;
  64. }(Parser);