StandAloneMonthParser.cjs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. exports.StandAloneMonthParser = void 0;
  3. var _constants = require("../constants.cjs");
  4. var _Parser = require("../Parser.cjs");
  5. var _utils = require("../utils.cjs");
  6. class StandAloneMonthParser extends _Parser.Parser {
  7. priority = 110;
  8. parse(dateString, token, match) {
  9. const valueCallback = (value) => value - 1;
  10. switch (token) {
  11. // 1, 2, ..., 12
  12. case "L":
  13. return (0, _utils.mapValue)(
  14. (0, _utils.parseNumericPattern)(
  15. _constants.numericPatterns.month,
  16. dateString,
  17. ),
  18. valueCallback,
  19. );
  20. // 01, 02, ..., 12
  21. case "LL":
  22. return (0, _utils.mapValue)(
  23. (0, _utils.parseNDigits)(2, dateString),
  24. valueCallback,
  25. );
  26. // 1st, 2nd, ..., 12th
  27. case "Lo":
  28. return (0, _utils.mapValue)(
  29. match.ordinalNumber(dateString, {
  30. unit: "month",
  31. }),
  32. valueCallback,
  33. );
  34. // Jan, Feb, ..., Dec
  35. case "LLL":
  36. return (
  37. match.month(dateString, {
  38. width: "abbreviated",
  39. context: "standalone",
  40. }) ||
  41. match.month(dateString, { width: "narrow", context: "standalone" })
  42. );
  43. // J, F, ..., D
  44. case "LLLLL":
  45. return match.month(dateString, {
  46. width: "narrow",
  47. context: "standalone",
  48. });
  49. // January, February, ..., December
  50. case "LLLL":
  51. default:
  52. return (
  53. match.month(dateString, { width: "wide", context: "standalone" }) ||
  54. match.month(dateString, {
  55. width: "abbreviated",
  56. context: "standalone",
  57. }) ||
  58. match.month(dateString, { width: "narrow", context: "standalone" })
  59. );
  60. }
  61. }
  62. validate(_date, value) {
  63. return value >= 0 && value <= 11;
  64. }
  65. set(date, _flags, value) {
  66. date.setMonth(value, 1);
  67. date.setHours(0, 0, 0, 0);
  68. return date;
  69. }
  70. incompatibleTokens = [
  71. "Y",
  72. "R",
  73. "q",
  74. "Q",
  75. "M",
  76. "w",
  77. "I",
  78. "D",
  79. "i",
  80. "e",
  81. "c",
  82. "t",
  83. "T",
  84. ];
  85. }
  86. exports.StandAloneMonthParser = StandAloneMonthParser;