Skip to content

Commit

Permalink
MAT-7570: Limit the range dates can be shifted to [0,9999]
Browse files Browse the repository at this point in the history
Years before 0 and after 9999 get funky (see ISO 8601) and are not, at this time, helpful to users.
  • Loading branch information
jkotanchik-SB committed Aug 27, 2024
1 parent ac83956 commit eda2c82
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>gov.cms.madie</groupId>
<artifactId>madie-java-models</artifactId>
<version>0.6.58-SNAPSHOT</version>
<version>0.6.59-SNAPSHOT</version>
<name>madie-java-models</name>
<description>Java based models for MADiE microservices</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public Interval shiftIntervalByYear(Interval interval, int year) {
return null;
}
if (interval.getLow() != null) {
interval.setLow(interval.getLow().plusYears(year));
interval.setLow(shiftDateByYear(interval.getLow(), year));
}
if (interval.getHigh() != null) {
interval.setHigh(interval.getHigh().plusYears(year));
interval.setHigh(shiftDateByYear(interval.getHigh(), year));
}
return interval;
}
Expand All @@ -129,6 +129,13 @@ public ZonedDateTime shiftDateByYear(ZonedDateTime dateTime, int year) {
if (dateTime == null) {
return null;
}
return dateTime.plusYears(year);
ZonedDateTime shiftedDateTime = dateTime.plusYears(year);
if (shiftedDateTime.getYear() > 9999) {
return shiftedDateTime.withYear(9999);
}
if (shiftedDateTime.getYear() < 0) {
return shiftedDateTime.withYear(0);
}
return shiftedDateTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gov.cms.madie.models.cqm.datacriteria.basetypes;

import gov.cms.madie.models.cqm.datacriteria.EncounterPerformed;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import static org.assertj.core.api.Assertions.assertThat;

class DataElementTest {

@Test
void shiftDateByYearAfterYear9999() {
EncounterPerformed encounterPerformed = new EncounterPerformed();
ZonedDateTime dateTime = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC"));
encounterPerformed.setAuthorDatetime(dateTime);
ZonedDateTime shiftedDateTime = encounterPerformed.shiftDateByYear(dateTime, 100000);
assertThat(shiftedDateTime).isEqualTo(dateTime.withYear(9999));
}

@Test
void shiftDateByYearBeforeYear0() {
EncounterPerformed encounterPerformed = new EncounterPerformed();
ZonedDateTime dateTime = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC"));
encounterPerformed.setAuthorDatetime(dateTime);
ZonedDateTime shiftedDateTime = encounterPerformed.shiftDateByYear(dateTime, -100000);
assertThat(shiftedDateTime).isEqualTo(dateTime.withYear(0));
}
}

0 comments on commit eda2c82

Please sign in to comment.