As pointed out in #41, a date format like "20191123" cannot be
parsed using a strict interpretation of CLDR patterns, since
there is no way to specify that a year should occupy exactly
n (= 4) digits. CLDR itself advocates "lenient parsing" as a
general approach, which I think is a terrible idea (not that
lenient parsing is per se a bad idea but that it's an awful
default).
This PR allows formats like the above to be parsed by treating
year pattern specially. If the pattern following a year pattern
is numeric, then we will treat the year pattern as specifying
an exact number of digits to parse, instead of a minimum. This
is a trick that the Joda-Time library uses, and it seems like
a reasonable and simple approach.
Note that non-year patterns do not work this way, since they
typically already have sensible behavior. A pattern of "M,"
for example, matches at least one digit as a month -- but it
also has a built-in maximum of two digits. There seems no
point in saying that "M" should match exactly one digit when
the following pattern is numeric, because no sensible date
format would insist on matching exactly one digit for a month.
As pointed out in #41, a date format like "20191123" cannot be parsed using a strict interpretation of CLDR patterns, since there is no way to specify that a year should occupy exactly n (= 4) digits. CLDR itself advocates "lenient parsing" as a general approach, which I think is a terrible idea (not that lenient parsing is per se a bad idea but that it's an awful default).
This PR allows formats like the above to be parsed by treating year pattern specially. If the pattern following a year pattern is numeric, then we will treat the year pattern as specifying an exact number of digits to parse, instead of a minimum. This is a trick that the Joda-Time library uses, and it seems like a reasonable and simple approach.
Note that non-year patterns do not work this way, since they typically already have sensible behavior. A pattern of "M," for example, matches at least one digit as a month -- but it also has a built-in maximum of two digits. There seems no point in saying that "M" should match exactly one digit when the following pattern is numeric, because no sensible date format would insist on matching exactly one digit for a month.