DayParser.cjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. exports.DayParser = void 0;
  3. var _index = require("../../../setDay.cjs");
  4. var _Parser = require("../Parser.cjs");
  5. // Day of week
  6. class DayParser extends _Parser.Parser {
  7. priority = 90;
  8. parse(dateString, token, match) {
  9. switch (token) {
  10. // Tue
  11. case "E":
  12. case "EE":
  13. case "EEE":
  14. return (
  15. match.day(dateString, {
  16. width: "abbreviated",
  17. context: "formatting",
  18. }) ||
  19. match.day(dateString, { width: "short", context: "formatting" }) ||
  20. match.day(dateString, { width: "narrow", context: "formatting" })
  21. );
  22. // T
  23. case "EEEEE":
  24. return match.day(dateString, {
  25. width: "narrow",
  26. context: "formatting",
  27. });
  28. // Tu
  29. case "EEEEEE":
  30. return (
  31. match.day(dateString, { width: "short", context: "formatting" }) ||
  32. match.day(dateString, { width: "narrow", context: "formatting" })
  33. );
  34. // Tuesday
  35. case "EEEE":
  36. default:
  37. return (
  38. match.day(dateString, { width: "wide", context: "formatting" }) ||
  39. match.day(dateString, {
  40. width: "abbreviated",
  41. context: "formatting",
  42. }) ||
  43. match.day(dateString, { width: "short", context: "formatting" }) ||
  44. match.day(dateString, { width: "narrow", context: "formatting" })
  45. );
  46. }
  47. }
  48. validate(_date, value) {
  49. return value >= 0 && value <= 6;
  50. }
  51. set(date, _flags, value, options) {
  52. date = (0, _index.setDay)(date, value, options);
  53. date.setHours(0, 0, 0, 0);
  54. return date;
  55. }
  56. incompatibleTokens = ["D", "i", "e", "c", "t", "T"];
  57. }
  58. exports.DayParser = DayParser;