diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java index 4c7c5c105b5..692be7da6a9 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java @@ -285,7 +285,7 @@ public abstract class BaseDateTimeDt extends BasePrimitive { cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum)); precision = TemporalPrecisionEnum.DAY; if (length > 10) { - validateLengthIsAtLeast(value, 17); + validateLengthIsAtLeast(value, 16); validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss int offsetIdx = getOffsetIndex(value); String time; diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java index d681759fac5..7d5ce8aef60 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java @@ -569,6 +569,29 @@ public class BaseDateTimeDtDstu2Test { dt.setValueAsString("201302"); } + @Test + public void testParseMinute() throws DataFormatException { + DateTimeDt dt = new DateTimeDt(); + dt.setValueAsString("2013-02-03T11:22"); + + assertEquals("2013-02-03 11:22", myDateInstantParser.format(dt.getValue()).substring(0, 16)); + assertEquals("2013-02-03T11:22", dt.getValueAsString()); + assertEquals(false, dt.isTimeZoneZulu()); + assertNull(dt.getTimeZone()); + assertEquals(TemporalPrecisionEnum.MINUTE, dt.getPrecision()); + } + + @Test + public void testParseMinuteZulu() throws DataFormatException { + DateTimeDt dt = new DateTimeDt(); + dt.setValueAsString("2013-02-03T11:22Z"); + + assertEquals("2013-02-03T11:22Z", dt.getValueAsString()); + assertEquals(true, dt.isTimeZoneZulu()); + assertEquals("GMT", dt.getTimeZone().getID()); + assertEquals(TemporalPrecisionEnum.MINUTE, dt.getPrecision()); + } + @Test public void testParseSecond() throws DataFormatException { DateTimeDt dt = new DateTimeDt(); @@ -582,7 +605,7 @@ public class BaseDateTimeDtDstu2Test { } @Test - public void testParseSecondulu() throws DataFormatException { + public void testParseSecondZulu() throws DataFormatException { DateTimeDt dt = new DateTimeDt(); dt.setValueAsString("2013-02-03T11:22:33Z"); diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/BaseDateTimeType.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/BaseDateTimeType.java index 2a86454e549..0e09ec8a1fd 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/BaseDateTimeType.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/BaseDateTimeType.java @@ -404,7 +404,7 @@ public abstract class BaseDateTimeType extends PrimitiveType { cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum)); precision = TemporalPrecisionEnum.DAY; if (length > 10) { - validateLengthIsAtLeast(value, 17); + validateLengthIsAtLeast(value, 16); validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss int offsetIdx = getOffsetIndex(value); String time; diff --git a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java index 1ccaf67954c..33890acb3e7 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/model/BaseDateTimeTypeDstu3Test.java @@ -1,9 +1,16 @@ package org.hl7.fhir.dstu3.model; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.either; -import static org.hamcrest.Matchers.endsWith; -import static org.junit.Assert.*; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.parser.DataFormatException; +import ca.uhn.fhir.util.TestUtil; +import ca.uhn.fhir.validation.ValidationResult; +import org.apache.commons.lang3.time.FastDateFormat; +import org.hamcrest.Matchers; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import java.text.SimpleDateFormat; import java.time.LocalDateTime; @@ -14,20 +21,8 @@ import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; -import org.apache.commons.lang3.time.FastDateFormat; -import org.hamcrest.Matchers; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.parser.DataFormatException; -import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.validation.ValidationResult; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; public class BaseDateTimeTypeDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); @@ -458,7 +453,7 @@ public class BaseDateTimeTypeDstu3Test { dt.setValueAsString("1974-12-25+10:00"); fail(); } catch (ca.uhn.fhir.parser.DataFormatException e) { - assertEquals("Invalid date/time format: \"1974-12-25+10:00\"", e.getMessage()); + assertEquals("Invalid date/time format: \"1974-12-25+10:00\": Expected character 'T' at index 10 but found +", e.getMessage()); } try { DateTimeType dt = new DateTimeType(); @@ -540,6 +535,29 @@ public class BaseDateTimeTypeDstu3Test { dt.setValueAsString("201302"); } + @Test + public void testParseMinute() throws DataFormatException { + DateTimeType dt = new DateTimeType(); + dt.setValueAsString("2013-02-03T11:22"); + + assertEquals("2013-02-03 11:22", myDateInstantParser.format(dt.getValue()).substring(0, 16)); + assertEquals("2013-02-03T11:22", dt.getValueAsString()); + assertEquals(false, dt.isTimeZoneZulu()); + assertNull(dt.getTimeZone()); + assertEquals(TemporalPrecisionEnum.MINUTE, dt.getPrecision()); + } + + @Test + public void testParseMinuteZulu() throws DataFormatException { + DateTimeType dt = new DateTimeType(); + dt.setValueAsString("2013-02-03T11:22Z"); + + assertEquals("2013-02-03T11:22Z", dt.getValueAsString()); + assertEquals(true, dt.isTimeZoneZulu()); + assertEquals("GMT", dt.getTimeZone().getID()); + assertEquals(TemporalPrecisionEnum.MINUTE, dt.getPrecision()); + } + @Test public void testParseSecond() throws DataFormatException { DateTimeType dt = new DateTimeType(); @@ -553,7 +571,7 @@ public class BaseDateTimeTypeDstu3Test { } @Test - public void testParseSecondulu() throws DataFormatException { + public void testParseSecondZulu() throws DataFormatException { DateTimeType dt = new DateTimeType(); dt.setValueAsString("2013-02-03T11:22:33Z"); diff --git a/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/instance/model/BaseDateTimeType.java b/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/instance/model/BaseDateTimeType.java index 0111c56a286..61ff8733f4c 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/instance/model/BaseDateTimeType.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/instance/model/BaseDateTimeType.java @@ -343,7 +343,7 @@ public abstract class BaseDateTimeType extends PrimitiveType { retVal = ourYearMonthDayTimeMilliFormat.parse(theValue); } } catch (ParseException p2) { - throw new IllegalArgumentException("Invalid data/time string (" + p2.getMessage() + "): " + theValue); + throw new IllegalArgumentException("Invalid date/time string (" + p2.getMessage() + "): " + theValue); } setTimeZone(theValue, hasMillis); setPrecision(TemporalPrecisionEnum.MILLI); @@ -357,7 +357,7 @@ public abstract class BaseDateTimeType extends PrimitiveType { retVal = ourYearMonthDayTimeFormat.parse(theValue); } } catch (ParseException p2) { - throw new IllegalArgumentException("Invalid data/time string (" + p2.getMessage() + "): " + theValue); + throw new IllegalArgumentException("Invalid date/time string (" + p2.getMessage() + "): " + theValue); } setTimeZone(theValue, hasMillis); @@ -372,7 +372,7 @@ public abstract class BaseDateTimeType extends PrimitiveType { retVal = ourYearMonthDayTimeMinsFormat.parse(theValue); } } catch (ParseException p2) { - throw new IllegalArgumentException("Invalid data/time string (" + p2.getMessage() + "): " + theValue, p2); + throw new IllegalArgumentException("Invalid date/time string (" + p2.getMessage() + "): " + theValue, p2); } setTimeZone(theValue, hasMillis);