Skip to content

Ignore [] brackets while capturing date with UNIFIED_DATE_TIMESTAMP #444

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

Merged
merged 2 commits into from
Jun 22, 2025
Merged
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
15 changes: 10 additions & 5 deletions api/src/main/java/com/microsoft/gctoolkit/time/DateTimeStamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static double ageFromString(String doubleFormat) {
private static final String TIME = INTEGER + DECIMAL_POINT + "\\d{3}";

// Unified Tokens
private static final String DATE_TAG = "\\[" + DATE + "]";
private static final String DATE_TAG = "\\[(" + DATE + ")]";
private static final String UPTIME_TAG = "\\[(" + TIME + ")s]";

// Pre-unified tokens
Expand All @@ -81,15 +81,20 @@ private static double ageFromString(String doubleFormat) {

public static DateTimeStamp fromGCLogLine(String line) {
Matcher matcher;
int captureGroup = 2;
int dateCaptureGroup;
int ageCaptureGroup;
if ( line.startsWith("[")) {
matcher = UNIFIED_DATE_TIMESTAMP.matcher(line);
captureGroup = 3;
} else
dateCaptureGroup = 2;
ageCaptureGroup = 4;
} else {
matcher = PREUNIFIED_DATE_TIMESTAMP.matcher(line);
dateCaptureGroup = 1;
ageCaptureGroup = 2;
}

if ( matcher.find())
return new DateTimeStamp(dateFromString(matcher.group(1)), ageFromString(matcher.group(captureGroup)));
return new DateTimeStamp(dateFromString(matcher.group(dateCaptureGroup)), ageFromString(matcher.group(ageCaptureGroup)));
else
return EMPTY_DATE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,12 @@ void malformedDateTimeStampThrowsException() {
assertThrows(IllegalStateException.class, () -> onlyDate.after(onlyTime));
}

@Test
void shouldParseGCLogLineWithBrackets() {
final String dateTimeString = "2025-05-08T11:07:55.681+0530";
final String gcLogLine = "[" + dateTimeString + "][gc,phases ] GC(4) Other: 0.2ms";
final DateTimeStamp dateTimeStamp = DateTimeStamp.fromGCLogLine(gcLogLine);
final ZonedDateTime expected = ZonedDateTime.from(formatter.parse(dateTimeString));
assertTrue(expected.isEqual(dateTimeStamp.getDateTime()));
}
}