parsers.mjs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { EraParser } from "./parsers/EraParser.mjs";
  2. import { YearParser } from "./parsers/YearParser.mjs";
  3. import { LocalWeekYearParser } from "./parsers/LocalWeekYearParser.mjs";
  4. import { ISOWeekYearParser } from "./parsers/ISOWeekYearParser.mjs";
  5. import { ExtendedYearParser } from "./parsers/ExtendedYearParser.mjs";
  6. import { QuarterParser } from "./parsers/QuarterParser.mjs";
  7. import { StandAloneQuarterParser } from "./parsers/StandAloneQuarterParser.mjs";
  8. import { MonthParser } from "./parsers/MonthParser.mjs";
  9. import { StandAloneMonthParser } from "./parsers/StandAloneMonthParser.mjs";
  10. import { LocalWeekParser } from "./parsers/LocalWeekParser.mjs";
  11. import { ISOWeekParser } from "./parsers/ISOWeekParser.mjs";
  12. import { DateParser } from "./parsers/DateParser.mjs";
  13. import { DayOfYearParser } from "./parsers/DayOfYearParser.mjs";
  14. import { DayParser } from "./parsers/DayParser.mjs";
  15. import { LocalDayParser } from "./parsers/LocalDayParser.mjs";
  16. import { StandAloneLocalDayParser } from "./parsers/StandAloneLocalDayParser.mjs";
  17. import { ISODayParser } from "./parsers/ISODayParser.mjs";
  18. import { AMPMParser } from "./parsers/AMPMParser.mjs";
  19. import { AMPMMidnightParser } from "./parsers/AMPMMidnightParser.mjs";
  20. import { DayPeriodParser } from "./parsers/DayPeriodParser.mjs";
  21. import { Hour1to12Parser } from "./parsers/Hour1to12Parser.mjs";
  22. import { Hour0to23Parser } from "./parsers/Hour0to23Parser.mjs";
  23. import { Hour0To11Parser } from "./parsers/Hour0To11Parser.mjs";
  24. import { Hour1To24Parser } from "./parsers/Hour1To24Parser.mjs";
  25. import { MinuteParser } from "./parsers/MinuteParser.mjs";
  26. import { SecondParser } from "./parsers/SecondParser.mjs";
  27. import { FractionOfSecondParser } from "./parsers/FractionOfSecondParser.mjs";
  28. import { ISOTimezoneWithZParser } from "./parsers/ISOTimezoneWithZParser.mjs";
  29. import { ISOTimezoneParser } from "./parsers/ISOTimezoneParser.mjs";
  30. import { TimestampSecondsParser } from "./parsers/TimestampSecondsParser.mjs";
  31. import { TimestampMillisecondsParser } from "./parsers/TimestampMillisecondsParser.mjs";
  32. /*
  33. * | | Unit | | Unit |
  34. * |-----|--------------------------------|-----|--------------------------------|
  35. * | a | AM, PM | A* | Milliseconds in day |
  36. * | b | AM, PM, noon, midnight | B | Flexible day period |
  37. * | c | Stand-alone local day of week | C* | Localized hour w/ day period |
  38. * | d | Day of month | D | Day of year |
  39. * | e | Local day of week | E | Day of week |
  40. * | f | | F* | Day of week in month |
  41. * | g* | Modified Julian day | G | Era |
  42. * | h | Hour [1-12] | H | Hour [0-23] |
  43. * | i! | ISO day of week | I! | ISO week of year |
  44. * | j* | Localized hour w/ day period | J* | Localized hour w/o day period |
  45. * | k | Hour [1-24] | K | Hour [0-11] |
  46. * | l* | (deprecated) | L | Stand-alone month |
  47. * | m | Minute | M | Month |
  48. * | n | | N | |
  49. * | o! | Ordinal number modifier | O* | Timezone (GMT) |
  50. * | p | | P | |
  51. * | q | Stand-alone quarter | Q | Quarter |
  52. * | r* | Related Gregorian year | R! | ISO week-numbering year |
  53. * | s | Second | S | Fraction of second |
  54. * | t! | Seconds timestamp | T! | Milliseconds timestamp |
  55. * | u | Extended year | U* | Cyclic year |
  56. * | v* | Timezone (generic non-locat.) | V* | Timezone (location) |
  57. * | w | Local week of year | W* | Week of month |
  58. * | x | Timezone (ISO-8601 w/o Z) | X | Timezone (ISO-8601) |
  59. * | y | Year (abs) | Y | Local week-numbering year |
  60. * | z* | Timezone (specific non-locat.) | Z* | Timezone (aliases) |
  61. *
  62. * Letters marked by * are not implemented but reserved by Unicode standard.
  63. *
  64. * Letters marked by ! are non-standard, but implemented by date-fns:
  65. * - `o` modifies the previous token to turn it into an ordinal (see `parse` docs)
  66. * - `i` is ISO day of week. For `i` and `ii` is returns numeric ISO week days,
  67. * i.e. 7 for Sunday, 1 for Monday, etc.
  68. * - `I` is ISO week of year, as opposed to `w` which is local week of year.
  69. * - `R` is ISO week-numbering year, as opposed to `Y` which is local week-numbering year.
  70. * `R` is supposed to be used in conjunction with `I` and `i`
  71. * for universal ISO week-numbering date, whereas
  72. * `Y` is supposed to be used in conjunction with `w` and `e`
  73. * for week-numbering date specific to the locale.
  74. */
  75. // eslint-disable-next-line @typescript-eslint/no-explicit-any -- It's ok, we want any here
  76. export const parsers = {
  77. G: new EraParser(),
  78. y: new YearParser(),
  79. Y: new LocalWeekYearParser(),
  80. R: new ISOWeekYearParser(),
  81. u: new ExtendedYearParser(),
  82. Q: new QuarterParser(),
  83. q: new StandAloneQuarterParser(),
  84. M: new MonthParser(),
  85. L: new StandAloneMonthParser(),
  86. w: new LocalWeekParser(),
  87. I: new ISOWeekParser(),
  88. d: new DateParser(),
  89. D: new DayOfYearParser(),
  90. E: new DayParser(),
  91. e: new LocalDayParser(),
  92. c: new StandAloneLocalDayParser(),
  93. i: new ISODayParser(),
  94. a: new AMPMParser(),
  95. b: new AMPMMidnightParser(),
  96. B: new DayPeriodParser(),
  97. h: new Hour1to12Parser(),
  98. H: new Hour0to23Parser(),
  99. K: new Hour0To11Parser(),
  100. k: new Hour1To24Parser(),
  101. m: new MinuteParser(),
  102. s: new SecondParser(),
  103. S: new FractionOfSecondParser(),
  104. X: new ISOTimezoneWithZParser(),
  105. x: new ISOTimezoneParser(),
  106. t: new TimestampSecondsParser(),
  107. T: new TimestampMillisecondsParser(),
  108. };