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

Merge master to develop #19

Merged
merged 4 commits into from
Jan 11, 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
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));
}
}
Loading