parsers.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { EraParser } from "./parsers/EraParser.js";
  2. import { YearParser } from "./parsers/YearParser.js";
  3. import { LocalWeekYearParser } from "./parsers/LocalWeekYearParser.js";
  4. import { ISOWeekYearParser } from "./parsers/ISOWeekYearParser.js";
  5. import { ExtendedYearParser } from "./parsers/ExtendedYearParser.js";
  6. import { QuarterParser } from "./parsers/QuarterParser.js";
  7. import { StandAloneQuarterParser } from "./parsers/StandAloneQuarterParser.js";
  8. import { MonthParser } from "./parsers/MonthParser.js";
  9. import { StandAloneMonthParser } from "./parsers/StandAloneMonthParser.js";
  10. import { LocalWeekParser } from "./parsers/LocalWeekParser.js";
  11. import { ISOWeekParser } from "./parsers/ISOWeekParser.js";
  12. import { DateParser } from "./parsers/DateParser.js";
  13. import { DayOfYearParser } from "./parsers/DayOfYearParser.js";
  14. import { DayParser } from "./parsers/DayParser.js";
  15. import { LocalDayParser } from "./parsers/LocalDayParser.js";
  16. import { StandAloneLocalDayParser } from "./parsers/StandAloneLocalDayParser.js";
  17. import { ISODayParser } from "./parsers/ISODayParser.js";
  18. import { AMPMParser } from "./parsers/AMPMParser.js";
  19. import { AMPMMidnightParser } from "./parsers/AMPMMidnightParser.js";
  20. import { DayPeriodParser } from "./parsers/DayPeriodParser.js";
  21. import { Hour1to12Parser } from "./parsers/Hour1to12Parser.js";
  22. import { Hour0to23Parser } from "./parsers/Hour0to23Parser.js";
  23. import { Hour0To11Parser } from "./parsers/Hour0To11Parser.js";
  24. import { Hour1To24Parser } from "./parsers/Hour1To24Parser.js";
  25. import { MinuteParser } from "./parsers/MinuteParser.js";
  26. import { SecondParser } from "./parsers/SecondParser.js";
  27. import { FractionOfSecondParser } from "./parsers/FractionOfSecondParser.js";
  28. import { ISOTimezoneWithZParser } from "./parsers/ISOTimezoneWithZParser.js";
  29. import { ISOTimezoneParser } from "./parsers/ISOTimezoneParser.js";
  30. import { TimestampSecondsParser } from "./parsers/TimestampSecondsParser.js";
  31. import { TimestampMillisecondsParser } from "./parsers/TimestampMillisecondsParser.js";
  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. export const parsers = {
  76. G: new EraParser(),
  77. y: new YearParser(),
  78. Y: new LocalWeekYearParser(),
  79. R: new ISOWeekYearParser(),
  80. u: new ExtendedYearParser(),
  81. Q: new QuarterParser(),
  82. q: new StandAloneQuarterParser(),
  83. M: new MonthParser(),
  84. L: new StandAloneMonthParser(),
  85. w: new LocalWeekParser(),
  86. I: new ISOWeekParser(),
  87. d: new DateParser(),
  88. D: new DayOfYearParser(),
  89. E: new DayParser(),
  90. e: new LocalDayParser(),
  91. c: new StandAloneLocalDayParser(),
  92. i: new ISODayParser(),
  93. a: new AMPMParser(),
  94. b: new AMPMMidnightParser(),
  95. B: new DayPeriodParser(),
  96. h: new Hour1to12Parser(),
  97. H: new Hour0to23Parser(),
  98. K: new Hour0To11Parser(),
  99. k: new Hour1To24Parser(),
  100. m: new MinuteParser(),
  101. s: new SecondParser(),
  102. S: new FractionOfSecondParser(),
  103. X: new ISOTimezoneWithZParser(),
  104. x: new ISOTimezoneParser(),
  105. t: new TimestampSecondsParser(),
  106. T: new TimestampMillisecondsParser(),
  107. };