Class CalendarNames

java.lang.Object
io.github.connellite.util.internal.dateparse.CalendarNames

public final class CalendarNames extends Object
Case-insensitive lookup tables for month names, weekday names, AM/PM markers and time-zone abbreviations, used by DateTimeScanner.

Lookups take a range of a CharSequence and allocate nothing: keys are stored pre-normalized (lower-cased, without a trailing '.') in an open-addressed table and compared character by character.

primary() covers English, Russian and the default locale and is built eagerly. global() additionally covers one locale per language known to the JDK and is built on first use, because that build walks a few hundred locales. Tokens that mean different months in different languages are dropped from the global table unless the primary table defines them.

Based on sqlite-jdbc: FastDateParser.getDisplayNames and CaseInsensitiveTextStrategy, which collect every style a locale renders and lower-case the names once up front; the alternation regex they build is replaced here by a table that can be probed without allocating.

  • Field Details

  • Method Details

    • primary

      public static CalendarNames primary()
      Returns:
      names of English, Russian and the default locale
    • global

      public static CalendarNames global()
      Returns:
      primary names plus one locale per JDK language; the first call builds the tables
    • monthOf

      public int monthOf(CharSequence text, int start, int end)
      Returns:
      month number 1-12, or NOT_FOUND
    • isWeekday

      public boolean isWeekday(CharSequence text, int start, int end)
      Returns:
      true when the range names a day of the week
    • amPmOf

      public int amPmOf(CharSequence text, int start, int end)
      Returns:
      AM, PM, or NOT_FOUND
    • zoneOffsetSecondsOf

      public static int zoneOffsetSecondsOf(CharSequence text, int start, int end)
      Resolves a time-zone abbreviation to a fixed offset.

      Abbreviations are inherently ambiguous across regions (CST and IST name several zones); the most widely used reading is applied, as other lenient parsers do.

      Based on sqlite-jdbc: FastDateParser.TimeZoneStrategy, which resolves them from DateFormatSymbols.getZoneStrings() per locale instead.

      Returns:
      offset in seconds, or NOT_FOUND