Skip to content

Commit

Permalink
Small fix to DateRoller to work when diff spans new year
Browse files Browse the repository at this point in the history
  • Loading branch information
sliver007 committed Jan 30, 2025
1 parent eaa742e commit 862a612
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.gson.JsonObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
Expand All @@ -32,6 +33,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand Down Expand Up @@ -250,7 +252,11 @@ public boolean getAllDateElements(FhirContext fhirContext, IBaseResource resourc
}

private int getDaysBetweenDates(LocalDate start, LocalDate end) {
return end.getDayOfYear() - start.getDayOfYear();
try {
return Math.toIntExact(ChronoUnit.DAYS.between(start, end));
} catch (ArithmeticException e) {
throw new InvalidOperationException("DateRoller getDaysBetweenDates calculated a different that is too large for an integer.");
}
}

private LocalDate getLastUpdatedDate(IBaseResource resource) {
Expand Down

0 comments on commit 862a612

Please sign in to comment.