JAVA-11421 Update article - RegEx for matching Date Pattern in Java
This commit is contained in:
		
							parent
							
								
									9c61c1ce39
								
							
						
					
					
						commit
						d46b2d0684
					
				| @ -7,7 +7,7 @@ import java.util.regex.Pattern; | ||||
| public class February29thMatcher implements DateMatcher { | ||||
| 
 | ||||
|     private static final Pattern DATE_PATTERN = Pattern.compile( | ||||
|             "^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$"); | ||||
|             "^((2000|2400|2800|(19|2[0-9])(0[48]|[2468][048]|[13579][26]))-02-29)$"); | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean matches(String date) { | ||||
|  | ||||
| @ -7,7 +7,7 @@ import java.util.regex.Pattern; | ||||
| class GregorianDateMatcher implements DateMatcher { | ||||
| 
 | ||||
|     private static final Pattern DATE_PATTERN = Pattern.compile( | ||||
|             "^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$"  | ||||
|             "^((2000|2400|2800|(19|2[0-9])(0[48]|[2468][048]|[13579][26]))-02-29)$"  | ||||
|             + "|^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$" | ||||
|             + "|^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$"  | ||||
|             + "|^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$"); | ||||
|  | ||||
| @ -37,6 +37,8 @@ public class GregorianDateTestHelper { | ||||
|     } | ||||
| 
 | ||||
|     public void assertFebruary29th() { | ||||
|     	Assert.assertTrue(matcher.matches("1904-02-29")); | ||||
|     	Assert.assertTrue(matcher.matches("1996-02-29")); | ||||
|         Assert.assertTrue(matcher.matches("2000-02-29")); | ||||
|         Assert.assertTrue(matcher.matches("2400-02-29")); | ||||
|         Assert.assertTrue(matcher.matches("2800-02-29")); | ||||
| @ -44,6 +46,8 @@ public class GregorianDateTestHelper { | ||||
|         Assert.assertTrue(matcher.matches("2024-02-29")); | ||||
|         Assert.assertTrue(matcher.matches("2028-02-29")); | ||||
| 
 | ||||
|         Assert.assertFalse(matcher.matches("1900-02-29")); | ||||
|         Assert.assertFalse(matcher.matches("1999-02-29")); | ||||
|         Assert.assertFalse(matcher.matches("2017-02-29")); | ||||
|         Assert.assertFalse(matcher.matches("2018-02-29")); | ||||
|         Assert.assertFalse(matcher.matches("2019-02-29")); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user