diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5470762..6cd57ea 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/gradle.properties b/gradle.properties index dfe5c50..3214e26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java index 75d7c11..3f1dab4 100644 --- a/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java +++ b/src/main/java/com/epam/ta/reportportal/ws/reporting/databind/MultiFormatDateDeserializer.java @@ -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; @@ -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 } @@ -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); + } } diff --git a/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java b/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java index 68698eb..6860e1f 100644 --- a/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java +++ b/src/test/java/com/epam/ta/reportportal/ws/reporting/deserializers/MultiFormatDateDeserializerTest.java @@ -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; @@ -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, @@ -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)); } }