Merge pull request #903 from hapifhir/do-datetimetype-gregorian-zero

Fix DateTimeType inconsistencies when using field setting
This commit is contained in:
Grahame Grieve 2022-08-26 06:43:03 +10:00 committed by GitHub
commit ac9a1fc2c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 150 additions and 5 deletions

View File

@ -675,7 +675,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
validateValueInRange(theValue, theMinimum, theMaximum);
Calendar cal;
if (getValue() == null) {
cal = new GregorianCalendar(0, 0, 0);
cal = new GregorianCalendar();
} else {
cal = getValueAsCalendar();
}

View File

@ -0,0 +1,29 @@
package org.hl7.fhir.dstu2016may.model;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateTimeTypeFieldTests {
@Test
public void testFieldSet() {
final int YEAR = 1979;
final int MONTH = 0; // January
final int DAY = 23;
final DateTimeType dateTimeYearFirst = new DateTimeType();
dateTimeYearFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeYearFirst.setYear(YEAR);
dateTimeYearFirst.setDay(DAY);
dateTimeYearFirst.setMonth(MONTH);
final DateTimeType dateTimeDayFirst = new DateTimeType();
dateTimeDayFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeDayFirst.setDay(DAY);
dateTimeDayFirst.setYear(YEAR);
dateTimeDayFirst.setMonth(MONTH);
assertEquals("1979-01-23",dateTimeDayFirst.asStringValue());
assertEquals("1979-01-23",dateTimeYearFirst.asStringValue());
}
}

View File

@ -539,7 +539,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
validateValueInRange(theValue, theMinimum, theMaximum);
Calendar cal;
if (getValue() == null) {
cal = new GregorianCalendar(0, 0, 0);
cal = new GregorianCalendar();
} else {
cal = getValueAsCalendar();
}

View File

@ -0,0 +1,29 @@
package org.hl7.fhir.dstu3.model;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateTimeTypeFieldTests {
@Test
public void testFieldSet() {
final int YEAR = 1979;
final int MONTH = 0; // January
final int DAY = 23;
final DateTimeType dateTimeYearFirst = new DateTimeType();
dateTimeYearFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeYearFirst.setYear(YEAR);
dateTimeYearFirst.setDay(DAY);
dateTimeYearFirst.setMonth(MONTH);
final DateTimeType dateTimeDayFirst = new DateTimeType();
dateTimeDayFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeDayFirst.setDay(DAY);
dateTimeDayFirst.setYear(YEAR);
dateTimeDayFirst.setMonth(MONTH);
assertEquals("1979-01-23",dateTimeDayFirst.asStringValue());
assertEquals("1979-01-23",dateTimeYearFirst.asStringValue());
}
}

View File

@ -537,7 +537,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
validateValueInRange(theValue, theMinimum, theMaximum);
Calendar cal;
if (getValue() == null) {
cal = new GregorianCalendar(0, 0, 0);
cal = new GregorianCalendar();
} else {
cal = getValueAsCalendar();
}

View File

@ -0,0 +1,29 @@
package org.hl7.fhir.r4.model;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateTimeTypeFieldTests {
@Test
public void testFieldSet() {
final int YEAR = 1979;
final int MONTH = 0; // January
final int DAY = 23;
final DateTimeType dateTimeYearFirst = new DateTimeType();
dateTimeYearFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeYearFirst.setYear(YEAR);
dateTimeYearFirst.setDay(DAY);
dateTimeYearFirst.setMonth(MONTH);
final DateTimeType dateTimeDayFirst = new DateTimeType();
dateTimeDayFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeDayFirst.setDay(DAY);
dateTimeDayFirst.setYear(YEAR);
dateTimeDayFirst.setMonth(MONTH);
assertEquals("1979-01-23",dateTimeDayFirst.asStringValue());
assertEquals("1979-01-23",dateTimeYearFirst.asStringValue());
}
}

View File

@ -544,7 +544,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
validateValueInRange(theValue, theMinimum, theMaximum);
Calendar cal;
if (getValue() == null) {
cal = new GregorianCalendar(0, 0, 0);
cal = new GregorianCalendar();
} else {
cal = getValueAsCalendar();
}

View File

@ -0,0 +1,29 @@
package org.hl7.fhir.r4b.model;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateTimeTypeFieldTests {
@Test
public void testFieldSet() {
final int YEAR = 1979;
final int MONTH = 0; // January
final int DAY = 23;
final DateTimeType dateTimeYearFirst = new DateTimeType();
dateTimeYearFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeYearFirst.setYear(YEAR);
dateTimeYearFirst.setDay(DAY);
dateTimeYearFirst.setMonth(MONTH);
final DateTimeType dateTimeDayFirst = new DateTimeType();
dateTimeDayFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeDayFirst.setDay(DAY);
dateTimeDayFirst.setYear(YEAR);
dateTimeDayFirst.setMonth(MONTH);
assertEquals("1979-01-23",dateTimeDayFirst.asStringValue());
assertEquals("1979-01-23",dateTimeYearFirst.asStringValue());
}
}

View File

@ -544,7 +544,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
validateValueInRange(theValue, theMinimum, theMaximum);
Calendar cal;
if (getValue() == null) {
cal = new GregorianCalendar(0, 0, 0);
cal = new GregorianCalendar();
} else {
cal = getValueAsCalendar();
}

View File

@ -0,0 +1,29 @@
package org.hl7.fhir.r5.model;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DateTimeTypeFieldTests {
@Test
public void testFieldSet() {
final int YEAR = 1979;
final int MONTH = 0; // January
final int DAY = 23;
final DateTimeType dateTimeYearFirst = new DateTimeType();
dateTimeYearFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeYearFirst.setYear(YEAR);
dateTimeYearFirst.setDay(DAY);
dateTimeYearFirst.setMonth(MONTH);
final DateTimeType dateTimeDayFirst = new DateTimeType();
dateTimeDayFirst.setPrecision(TemporalPrecisionEnum.DAY);
dateTimeDayFirst.setDay(DAY);
dateTimeDayFirst.setYear(YEAR);
dateTimeDayFirst.setMonth(MONTH);
assertEquals("1979-01-23",dateTimeDayFirst.asStringValue());
assertEquals("1979-01-23",dateTimeYearFirst.asStringValue());
}
}