DayPeriodParser.cjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. exports.DayPeriodParser = void 0;
  3. var _Parser = require("../Parser.cjs");
  4. var _utils = require("../utils.cjs");
  5. // in the morning, in the afternoon, in the evening, at night
  6. class DayPeriodParser extends _Parser.Parser {
  7. priority = 80;
  8. parse(dateString, token, match) {
  9. switch (token) {
  10. case "B":
  11. case "BB":
  12. case "BBB":
  13. return (
  14. match.dayPeriod(dateString, {
  15. width: "abbreviated",
  16. context: "formatting",
  17. }) ||
  18. match.dayPeriod(dateString, {
  19. width: "narrow",
  20. context: "formatting",
  21. })
  22. );
  23. case "BBBBB":
  24. return match.dayPeriod(dateString, {
  25. width: "narrow",
  26. context: "formatting",
  27. });
  28. case "BBBB":
  29. default:
  30. return (
  31. match.dayPeriod(dateString, {
  32. width: "wide",
  33. context: "formatting",
  34. }) ||
  35. match.dayPeriod(dateString, {
  36. width: "abbreviated",
  37. context: "formatting",
  38. }) ||
  39. match.dayPeriod(dateString, {
  40. width: "narrow",
  41. context: "formatting",
  42. })
  43. );
  44. }
  45. }
  46. set(date, _flags, value) {
  47. date.setHours((0, _utils.dayPeriodEnumToHours)(value), 0, 0, 0);
  48. return date;
  49. }
  50. incompatibleTokens = ["a", "b", "t", "T"];
  51. }
  52. exports.DayPeriodParser = DayPeriodParser;