use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.
the class ExtendedBoundsTests method unparsed.
/**
* Convert an extended bounds in parsed for into one in unparsed form.
*/
public static ExtendedBounds unparsed(ExtendedBounds template) {
// It'd probably be better to randomize the formatter
FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
String minAsStr = template.getMin() == null ? null : formatter.printer().print(new Instant(template.getMin()));
String maxAsStr = template.getMax() == null ? null : formatter.printer().print(new Instant(template.getMax()));
return new ExtendedBounds(minAsStr, maxAsStr);
}
use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.
the class SimpleJodaTests method assertDateFormatParsingThrowingException.
private void assertDateFormatParsingThrowingException(String pattern, String invalidDate) {
try {
FormatDateTimeFormatter formatter = Joda.forPattern(pattern);
DateTimeFormatter parser = formatter.parser();
parser.parseMillis(invalidDate);
fail(String.format(Locale.ROOT, "Expected parsing exception for pattern [%s] with date [%s], but did not happen", pattern, invalidDate));
} catch (IllegalArgumentException e) {
}
}
use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.
the class SimpleJodaTests method testIsoVsCustom.
public void testIsoVsCustom() {
DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC);
long millis = formatter.parseMillis("1970-01-01T00:00:00");
assertThat(millis, equalTo(0L));
formatter = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZone(DateTimeZone.UTC);
millis = formatter.parseMillis("1970/01/01 00:00:00");
assertThat(millis, equalTo(0L));
FormatDateTimeFormatter formatter2 = Joda.forPattern("yyyy/MM/dd HH:mm:ss");
millis = formatter2.parser().parseMillis("1970/01/01 00:00:00");
assertThat(millis, equalTo(0L));
}
use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.
the class SimpleJodaTests method testForInvalidDatesInEpochSecond.
public void testForInvalidDatesInEpochSecond() {
FormatDateTimeFormatter formatter = Joda.forPattern("epoch_second");
try {
formatter.parser().parseDateTime(randomFrom("invalid date", "12345678901234567", "12345678901234567890"));
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("Invalid format"));
}
}
use of org.elasticsearch.common.joda.FormatDateTimeFormatter in project elasticsearch by elastic.
the class SimpleJodaTests method assertValidDateFormatParsing.
private void assertValidDateFormatParsing(String pattern, String dateToParse, String expectedDate) {
FormatDateTimeFormatter formatter = Joda.forPattern(pattern);
assertThat(formatter.printer().print(formatter.parser().parseMillis(dateToParse)), is(expectedDate));
}
Aggregations