Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Bug Fix, add support for strict_date_optional_time (#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
penghuo authored Apr 7, 2020
1 parent f1d538f commit 9ed430f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private Date parseDateString(List<String> formats, String columnOriginalDate) {
try {
switch (columnFormat) {
case "date_optional_time":
case "strict_date_optional_time":
parsedDate = DateUtils.parseDate(
columnOriginalDate,
FORMAT_DOT_KIBANA_SAMPLE_DATA_LOGS_EXCEPTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class DateFormat {
static {
// Special cases that are parsed separately
formatMap.put("date_optional_time", "");
formatMap.put("strict_date_optional_time", "");
formatMap.put("epoch_millis", "");
formatMap.put("epoch_second", "");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,25 @@ public void testNullDateData()
verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue);
}

@Test
public void testStrictDateOptionalTimeOrEpochMillsShouldPass()
{
String columnName = "date_field";
String dateFormat = "strict_date_optional_time||epoch_millis";

String originalDateValue = "2015-01-01";
String expectedDateValue = "2015-01-01 00:00:00.000";
verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue);

originalDateValue = "2015-01-01T12:10:30Z";
expectedDateValue = "2015-01-01 12:10:30.000";
verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue);

originalDateValue = "1420070400001";
expectedDateValue = "2015-01-01 00:00:00.001";
verifyFormatting(columnName, dateFormat, originalDateValue, expectedDateValue);
}

private void verifyFormatting(String columnName, String dateFormatProperty, String originalDateValue, String expectedDateValue)
{
List<Schema.Column> columns = buildColumnList(columnName);
Expand Down

0 comments on commit 9ed430f

Please sign in to comment.