Class DateTimeScanner
The scanner walks the input once, classifies every run of digits or letters, and assigns it to
a field. Nothing is allocated for the input itself (no trim, no substring) and no
exception is thrown when the input does not match: scan(java.lang.CharSequence, int, int, io.github.connellite.util.internal.dateparse.CalendarNames, io.github.connellite.util.internal.dateparse.ParsedFields) simply returns false.
Recognised shapes include ISO and RFC 3339 date-times with offset or bracketed zone, SQL
timestamps, compact yyyyMMdd[THHmmss], numeric dates with a two-digit year resolved
against a sliding window, localized month and weekday names, ordinal day suffixes, AM/PM markers
and zone abbreviations. Day-month order in all-numeric dates is decided by
orderDayAndMonth().
Based on araddon/dateparse: ParseAny and its iterRunes state machine, which records the start and length of every field while scanning and derives the layout from them rather than trying patterns in turn. Digit-by-index reading of ISO fields also follows Jackson's ISO8601Utils.parse and pydantic/speedate's get_digit!.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanmayContainLocalizedNames(CharSequence text, int start, int end) Cheap test for whether consultingCalendarNames.global()could pay off: the input has to hold both a word that may be a month name and a number.static booleanscan(CharSequence text, int start, int end, CalendarNames names, ParsedFields out) Scanstextbetweenstartandendand fillsout.static booleanscan(CharSequence text, int start, int end, CalendarNames names, Boolean dayFirst, ParsedFields out) Same asscan(CharSequence, int, int, CalendarNames, ParsedFields), with the order of an ambiguous all-numeric date given explicitly.
-
Method Details
-
scan
public static boolean scan(CharSequence text, int start, int end, CalendarNames names, ParsedFields out) Scanstextbetweenstartandendand fillsout.- Parameters:
names- name tables to resolve month, weekday and AM/PM tokens with- Returns:
truewhen the whole range was recognised; whenfalseis returned the contents ofoutare undefined and the caller must reset or discard it
-
scan
public static boolean scan(CharSequence text, int start, int end, CalendarNames names, Boolean dayFirst, ParsedFields out) Same asscan(CharSequence, int, int, CalendarNames, ParsedFields), with the order of an ambiguous all-numeric date given explicitly.- Parameters:
dayFirst-trueto read an ambiguous pair as day-month,falseas month-day, ornullto follow the locale
-
mayContainLocalizedNames
Cheap test for whether consultingCalendarNames.global()could pay off: the input has to hold both a word that may be a month name and a number.
-