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:
@@ -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[][] { //
|
||||
|
||||
Reference in New Issue
Block a user