@@ -84,7 +84,10 @@ private DateTools() {
8484 * @should parse year ranges correctly
8585 * @should parse single years correctly
8686 * @should throw IllegalArgumentException if normalizeYearMinDigits less than 1
87+ * @should ignore values with too many digits
8788 */
89+ private static final int MAX_YEAR_DIGITS = 5 ;
90+
8891 static List <PrimitiveDate > normalizeDate (String dateString , int normalizeYearMinDigits ) {
8992 if (normalizeYearMinDigits < 1 ) {
9093 throw new IllegalArgumentException ("normalizeYearMinDigits must be at least 1" );
@@ -159,7 +162,7 @@ static List<PrimitiveDate> normalizeDate(String dateString, int normalizeYearMin
159162 while (m .find ()) {
160163 try {
161164 String sub = dateString .substring (m .start (), m .end ());
162- if (sub .length () >= normalizeYearMinDigits ) {
165+ if (sub .length () >= normalizeYearMinDigits && sub . length () <= MAX_YEAR_DIGITS ) {
163166 int year = Integer .parseInt (sub );
164167 ret .add (new PrimitiveDate (year , null , null ));
165168 }
@@ -175,7 +178,8 @@ static List<PrimitiveDate> normalizeDate(String dateString, int normalizeYearMin
175178 while (m .find ()) {
176179 try {
177180 String sub = dateString .substring (m .start (), m .end ());
178- if (sub .length () >= (sub .charAt (0 ) == '-' ? (normalizeYearMinDigits + 1 ) : normalizeYearMinDigits )) {
181+ int digitLength = sub .charAt (0 ) == '-' ? sub .length () - 1 : sub .length ();
182+ if (digitLength >= normalizeYearMinDigits && digitLength <= MAX_YEAR_DIGITS ) {
179183 int year = Integer .parseInt (sub );
180184 ret .add (new PrimitiveDate (year , null , null ));
181185 }
0 commit comments