add support for ISO-like date formats

Recommind is using a pseudo ISO date format for their
log files. It uses a comma instead of a dot for the
second to milli second separator and it does not
add a timezone. Dates without timezone are assumed to be UTC.
This commit is contained in:
2019-12-09 18:40:14 +01:00
parent 620f58d8e5
commit d383134c42
2 changed files with 44 additions and 8 deletions

View File

@@ -68,6 +68,34 @@ public class FastISODateParserTest {
Assert.assertEquals(actualDate, expectedDate.toInstant().toEpochMilli());
}
@DataProvider(name = "providerPseudoISODate")
public Object[][] providerPseudoISODate() {
return new Object[][] { //
{ "2018-11-18T14:42:49,123Z", "2018-11-18T14:42:49.123Z" }, // with comman instead of dot
{ "2018-11-18T14:42:49,123+12:34", "2018-11-18T14:42:49.123+12:34" }, // with comman instead of dot
{ "2018-11-18T14:42:49.123", "2018-11-18T14:42:49.123Z" }, // without timezone
{ "2018-11-18T14:42:49,123", "2018-11-18T14:42:49.123Z" }, // with command, without timezone
};
}
@Test(dataProvider = "providerPseudoISODate")
public void testParsePseudoISODate(final String date, final String expectedDate) {
final OffsetDateTime actualDate = new FastISODateParser().parse(date);
final OffsetDateTime expected = OffsetDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(expectedDate));
Assert.assertEquals(actualDate, expected);
}
@Test(dataProvider = "providerPseudoISODate")
public void testParsePseudoISODateAsEpochMilli(final String date, final String expectedDate) {
final long actualDate = new FastISODateParser().parseAsEpochMilli(date);
final OffsetDateTime expected = OffsetDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(expectedDate));
Assert.assertEquals(actualDate, expected.toInstant().toEpochMilli());
}
@DataProvider(name = "providerParseInvalidDate")
public Object[][] providerParseInvalidDate() {
return new Object[][] { //