Skip to content

Commit

Permalink
Merge pull request #18 from reportportal/rc/5.13.1
Browse files Browse the repository at this point in the history
Release 5.13.1
  • Loading branch information
pbortnik authored Jan 11, 2025
2 parents b98588a + 279ade8 commit ba11c68
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
env:
GH_USER_NAME: github.actor
SCRIPTS_VERSION: 5.12.0
RELEASE_VERSION: 5.13.0
RELEASE_VERSION: 5.13.1

jobs:
release:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=5.13.0
version=5.13.1
description=EPAM Report portal. REST Reporting API model
hibernateValidatorVersion=6.1.2.Final
validationApiVersion=2.0.1.Final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -67,14 +68,14 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th
try {
long longDate = parser.getLongValue();
if (parser.getText() == null) {
return Instant.ofEpochMilli(longDate);
return getTruncatedToMicros(longDate);
}
} catch (Exception e) {
// ignore
}
try {
long millis = Long.parseLong(parser.getText());
return Instant.ofEpochMilli(millis);
long longDate = Long.parseLong(parser.getText());
return getTruncatedToMicros(longDate);
} catch (Exception e) {
// ignore
}
Expand All @@ -85,12 +86,18 @@ public Instant deserialize(JsonParser parser, DeserializationContext context) th
try {
TemporalAccessor parsedDate = formatter.parseBest(strDate, ZonedDateTime::from,
LocalDateTime::from);
return parsedDate instanceof ZonedDateTime ? ((ZonedDateTime) parsedDate).toInstant()
: ((LocalDateTime) parsedDate).toInstant(ZoneOffset.UTC);
Instant instant =
parsedDate instanceof ZonedDateTime ? ((ZonedDateTime) parsedDate).toInstant()
: ((LocalDateTime) parsedDate).toInstant(ZoneOffset.UTC);
return instant.truncatedTo(ChronoUnit.MICROS);
} catch (DateTimeParseException e) {
// Exception means the text could not be parsed with this formatter, continue with next formatter
}
}
throw new IOException("Unable to parse date: " + strDate);
}

private Instant getTruncatedToMicros(long longDate) {
return Instant.ofEpochMilli(longDate).truncatedTo(ChronoUnit.MICROS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
@ExtendWith(MockitoExtension.class)
class MultiFormatDateDeserializerTest {

private static final Instant expectedTime = Instant.parse("2024-03-01T20:24:09.930Z");
private static final Instant expectedTime = Instant.parse("2024-03-01T20:24:09.930987Z");
private static final Instant expectedTimeMillis = Instant.parse("2024-03-01T20:24:09.930Z");

@Mock
JsonParser jsonParser;
Expand All @@ -46,22 +47,34 @@ class MultiFormatDateDeserializerTest {
@ValueSource(strings = {
"2024-03-01T20:24:09.930987Z",
"2024-03-01T20:24:09.930987654",
"2024-03-01T20:24:09.930987+0000",
"2024-03-01T20:24:09.930987999"
})
void deserializeDatesMicros(String strDate) throws IOException {
MultiFormatDateDeserializer a = new MultiFormatDateDeserializer();
when(jsonParser.getText()).thenReturn(strDate);
Instant date = a.deserialize(jsonParser, mock(DeserializationContext.class));

Assertions.assertEquals(expectedTime, date.truncatedTo(ChronoUnit.MICROS));
}

@ParameterizedTest
@ValueSource(strings = {
"2024-03-01T20:24:09.930Z",
"2024-03-01T20:24:09.930",
"2024-03-01T20:24:09.930+00:00",
"2024-03-01T19:24:09.930-01:00",
"2024-03-01T23:24:09.930+0300",
"2024-03-01T20:24:09.930000+0000",
"1709324649930"
})
void deserializeDates(String strDate) throws IOException {
void deserializeDatesMillis(String strDate) throws IOException {
MultiFormatDateDeserializer a = new MultiFormatDateDeserializer();
when(jsonParser.getText()).thenReturn(strDate);
Instant date = a.deserialize(jsonParser, mock(DeserializationContext.class));

Assertions.assertEquals(expectedTime, date.truncatedTo(ChronoUnit.MILLIS));
Assertions.assertEquals(expectedTimeMillis, date.truncatedTo(ChronoUnit.MICROS));
}


@ParameterizedTest
@ValueSource(longs = {
1709324649930L,
Expand All @@ -71,6 +84,6 @@ void deserializeIntegerFormat(Long longDate) throws IOException {
when(jsonParser.getLongValue()).thenReturn(longDate);
Instant date = a.deserialize(jsonParser, mock(DeserializationContext.class));

Assertions.assertEquals(expectedTime, date.truncatedTo(ChronoUnit.MILLIS));
Assertions.assertEquals(expectedTimeMillis, date.truncatedTo(ChronoUnit.MICROS));
}
}

0 comments on commit ba11c68

Please sign in to comment.