Merge pull request #903 from hapifhir/do-datetimetype-gregorian-zero
Fix DateTimeType inconsistencies when using field setting
This commit is contained in:
commit
ac9a1fc2c7
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue