1
0
mirror of https://github.com/pcvolkmer/mv64e-onkostar-data.git synced 2025-07-02 02:22:54 +00:00

fix: date alignment for different time zones

This commit is contained in:
2025-06-22 13:34:30 +02:00
parent 6a3ee860b7
commit bdf4bb0e23
2 changed files with 7 additions and 3 deletions

View File

@ -2,6 +2,8 @@ package dev.pcvolkmer.onco.datamapper;
import dev.pcvolkmer.onco.datamapper.exceptions.DataAccessException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.Map;
@ -124,7 +126,9 @@ public class ResultSet {
return null;
}
if (raw instanceof Date) {
return (Date) raw;
var localDate = LocalDate.parse(raw.toString());
// JSON Converter uses UTC timezone
return Date.from(localDate.atStartOfDay(ZoneId.of("UTC")).toInstant());
}
throw new IllegalArgumentException("Cannot convert " + raw.getClass() + " to Date");

View File

@ -37,7 +37,7 @@ class ResultSetTest {
void shouldReturnDateValues() {
var data = getTestData();
assertThat(data.getDate("date")).isEqualTo(new Date(Date.from(Instant.parse("2025-06-21T12:00:00Z")).getTime()));
assertThat(data.getDate("date")).isEqualTo(new Date(Date.from(Instant.parse("2025-06-21T00:00:00Z")).getTime()));
}
static ResultSet getTestData() {
@ -45,7 +45,7 @@ class ResultSetTest {
Map.of(
"string", "TestString",
"int", 42,
"date", new Date(Date.from(Instant.parse("2025-06-21T12:00:00Z")).getTime())
"date", new Date(Date.from(Instant.parse("2025-06-21T02:00:00Z")).getTime())
)
);
}