|
38 | 38 | import java.util.Locale;
|
39 | 39 |
|
40 | 40 | import static org.hamcrest.Matchers.containsString;
|
41 |
| -import static org.hamcrest.Matchers.equalTo; |
42 | 41 | import static org.hamcrest.Matchers.is;
|
| 42 | +import static org.hamcrest.core.IsEqual.equalTo; |
43 | 43 |
|
44 | 44 | public class JavaJodaTimeDuellingTests extends ESTestCase {
|
| 45 | + @Override |
| 46 | + protected boolean enableWarningsCheck() { |
| 47 | + return false; |
| 48 | + } |
| 49 | + // date_optional part of a parser names "strict_date_optional_time" or "date_optional"time |
| 50 | + // means that date part can be partially parsed. |
| 51 | + public void testPartialParsing() { |
| 52 | + assertSameDateAs("2001", "strict_date_optional_time_nanos", "strict_date_optional_time"); |
| 53 | + assertSameDateAs("2001-01", "strict_date_optional_time_nanos", "strict_date_optional_time"); |
| 54 | + assertSameDateAs("2001-01-01", "strict_date_optional_time_nanos", "strict_date_optional_time"); |
| 55 | + |
| 56 | + assertSameDate("2001", "strict_date_optional_time"); |
| 57 | + assertSameDate("2001-01", "strict_date_optional_time"); |
| 58 | + assertSameDate("2001-01-01", "strict_date_optional_time"); |
| 59 | + |
| 60 | + assertSameDate("2001", "date_optional_time"); |
| 61 | + assertSameDate("2001-01", "date_optional_time"); |
| 62 | + assertSameDate("2001-01-01", "date_optional_time"); |
| 63 | + |
| 64 | + |
| 65 | + assertSameDateAs("2001", "iso8601", "strict_date_optional_time"); |
| 66 | + assertSameDateAs("2001-01", "iso8601", "strict_date_optional_time"); |
| 67 | + assertSameDateAs("2001-01-01", "iso8601", "strict_date_optional_time"); |
| 68 | + |
| 69 | + assertSameDate("9999","date_optional_time||epoch_second"); |
| 70 | + } |
| 71 | + |
45 | 72 | public void testCompositeDateMathParsing(){
|
46 | 73 | //in all these examples the second pattern will be used
|
47 | 74 | assertDateMathEquals("2014-06-06T12:01:02.123", "yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS");
|
@@ -909,4 +936,10 @@ private void assertDateMathEquals(String text, String pattern) {
|
909 | 936 |
|
910 | 937 | assertEquals(gotMillisJoda, gotMillisJava);
|
911 | 938 | }
|
| 939 | + |
| 940 | + private void assertSameDateAs(String input, String javaPattern, String jodaPattern) { |
| 941 | + DateFormatter javaFormatter = DateFormatter.forPattern(javaPattern); |
| 942 | + DateFormatter jodaFormatter = Joda.forPattern(jodaPattern); |
| 943 | + assertSameDate(input, javaPattern, jodaFormatter, javaFormatter); |
| 944 | + } |
912 | 945 | }
|
0 commit comments