Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle zeroed out time when seconds are :00 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TimestampConverter implements CustomConverter<SchemaBuilder, Relati
public static final List<String> SUPPORTED_DATA_TYPES = List.of("date", "time", "datetime", "timestamp",
"datetime2");

private static final String DATETIME_REGEX = "(?<datetime>(?<date>(?:(?<year>\\d{4})-(?<month>\\d{1,2})-(?<day>\\d{1,2}))|(?:(?<day2>\\d{1,2})\\/(?<month2>\\d{1,2})\\/(?<year2>\\d{4}))|(?:(?<day3>\\d{1,2})-(?<month3>\\w{3})-(?<year3>\\d{4})))?(?:\\s?T?(?<time>(?<hour>\\d{1,2}):(?<minute>\\d{1,2}):(?<second>\\d{1,2})\\.?(?<milli>\\d{0,7})?)?))";
private static final String DATETIME_REGEX = "(?<datetime>(?<date>(?:(?<year>\\d{4})-(?<month>\\d{1,2})-(?<day>\\d{1,2}))|(?:(?<day2>\\d{1,2})\\/(?<month2>\\d{1,2})\\/(?<year2>\\d{4}))|(?:(?<day3>\\d{1,2})-(?<month3>\\w{3})-(?<year3>\\d{4})))?(?:\\s?T?(?<time>(?:(?<hour>\\d{1,2}):(?<minute>\\d{1,2}):(?<second>\\d{1,2}))\\.?(?<milli>\\d{0,7})|(?:(?<hour2>\\d{1,2}):(?<minute2>\\d{1,2}))?)?))";
private static final Pattern regexPattern = Pattern.compile(DATETIME_REGEX);

public String strDatetimeFormat, strDateFormat, strTimeFormat;
Expand Down Expand Up @@ -141,8 +141,10 @@ private Long milliFromDateString(String timestamp) {
: (matches.group("month2") != null ? matches.group("month2") : matches.group("month3")));
String day = (matches.group("day") != null ? matches.group("day")
: (matches.group("day2") != null ? matches.group("day2") : matches.group("day3")));
String hour = matches.group("hour") != null ? matches.group("hour") : "00";
String minute = matches.group("minute") != null ? matches.group("minute") : "00";
String hour = (matches.group("hour") != null ? matches.group("hour")
: (matches.group("hour2") != null ? matches.group("hour2") : "00"));
String minute = (matches.group("minute") != null ? matches.group("minute")
: (matches.group("minute2") != null ? matches.group("minute2") : "00"));
String second = matches.group("second") != null ? matches.group("second") : "00";
String milli = matches.group("milli") != null ? matches.group("milli") : "000";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ void configureTimeTest(final String inputFormat, final String expectedFormat) {
"datetime,, 19/04/2019 15:13:20.345123, 2019-04-19T15:13:20.345Z",
"datetime,, 2019-4-19 15:13:20.345123, 2019-04-19T15:13:20.345Z",
"datetime2,, 2019-4-19 15:13:20.345123, 2019-04-19T15:13:20.345Z",
"datetime,, 2019-4-19 3:1:0.345123, 2019-04-19T03:01:00.345Z", "datetime,YYYY-MM-dd,,", "timestamp,,,", "date,,,"})
"datetime,, 2019-4-19 3:1:0.345123, 2019-04-19T03:01:00.345Z",
"datetime,, 2019-4-19 15:13, 2019-04-19T15:13:00.000Z",
"datetime,YYYY-MM-dd,,", "timestamp,,,", "date,,,"})
void converterTest(final String columnType, final String format, final String input, final String expectedResult) {
final TimestampConverter tsConverter = new TimestampConverter();

Expand Down