Skip to content
Snippets Groups Projects

Resolve "Erreur lors du filtre pas date"

Merged VARLOTEAUX Lucile requested to merge 232--bug_filtre_interval_date into OA_V2_dev
3 files
+ 18
4
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -3,7 +3,9 @@ package fr.inra.oresing.domain.data.read.query;
import com.google.common.base.Strings;
import fr.inra.oresing.domain.exceptions.data.data.BadDownloadDatasetQuery;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Map;
@@ -24,14 +26,26 @@ public record IntervalValuesDate(
}
if (from != null) {
try {
fromDate = LocalDate.from(DateTimeFormatter.ofPattern(format).parse(from));
if (from.matches("[0-9]*")) {
ZoneId zone = ZoneId.of("UTC");
fromDate = LocalDate.ofInstant(Instant.ofEpochMilli(Long.valueOf(from)), zone);
from = fromDate.format(DateTimeFormatter.ofPattern(format));
} else {
fromDate = LocalDate.from(DateTimeFormatter.ofPattern(format).parse(from));
}
} catch (final DateTimeParseException e) {
throw new BadDownloadDatasetQuery(FILTER_BAD_FORMAT_FOR_START_DATE);
}
}
if (to != null) {
try {
toDate = LocalDate.from(DateTimeFormatter.ofPattern(format).parse(to));
if (to.matches("[0-9]*")) {
ZoneId zone = ZoneId.of("UTC");
toDate = LocalDate.ofInstant(Instant.ofEpochMilli(Long.valueOf(to)), zone);
to = toDate.format(DateTimeFormatter.ofPattern(format));
} else {
toDate = LocalDate.from(DateTimeFormatter.ofPattern(format).parse(to));
}
} catch (final DateTimeParseException e) {
throw new BadDownloadDatasetQuery(FILTER_BAD_FORMAT_FOR_END_DATE);
}
Loading