Revert "Allow MINUTE precision for datetimes. Closes #604"
This commit is contained in:
parent
401185baff
commit
c04146a76a
|
@ -285,7 +285,7 @@ public abstract class BaseDateTimeDt extends BasePrimitive<Date> {
|
||||||
cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
|
cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
|
||||||
precision = TemporalPrecisionEnum.DAY;
|
precision = TemporalPrecisionEnum.DAY;
|
||||||
if (length > 10) {
|
if (length > 10) {
|
||||||
validateLengthIsAtLeast(value, 16);
|
validateLengthIsAtLeast(value, 17);
|
||||||
validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss
|
validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss
|
||||||
int offsetIdx = getOffsetIndex(value);
|
int offsetIdx = getOffsetIndex(value);
|
||||||
String time;
|
String time;
|
||||||
|
|
|
@ -569,29 +569,6 @@ public class BaseDateTimeDtDstu2Test {
|
||||||
dt.setValueAsString("201302");
|
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
|
@Test
|
||||||
public void testParseSecond() throws DataFormatException {
|
public void testParseSecond() throws DataFormatException {
|
||||||
DateTimeDt dt = new DateTimeDt();
|
DateTimeDt dt = new DateTimeDt();
|
||||||
|
@ -605,7 +582,7 @@ public class BaseDateTimeDtDstu2Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseSecondZulu() throws DataFormatException {
|
public void testParseSecondulu() throws DataFormatException {
|
||||||
DateTimeDt dt = new DateTimeDt();
|
DateTimeDt dt = new DateTimeDt();
|
||||||
dt.setValueAsString("2013-02-03T11:22:33Z");
|
dt.setValueAsString("2013-02-03T11:22:33Z");
|
||||||
|
|
||||||
|
|
|
@ -404,7 +404,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
|
cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
|
||||||
precision = TemporalPrecisionEnum.DAY;
|
precision = TemporalPrecisionEnum.DAY;
|
||||||
if (length > 10) {
|
if (length > 10) {
|
||||||
validateLengthIsAtLeast(value, 16);
|
validateLengthIsAtLeast(value, 17);
|
||||||
validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss
|
validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss
|
||||||
int offsetIdx = getOffsetIndex(value);
|
int offsetIdx = getOffsetIndex(value);
|
||||||
String time;
|
String time;
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
package org.hl7.fhir.dstu3.model;
|
package org.hl7.fhir.dstu3.model;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import ca.uhn.fhir.parser.DataFormatException;
|
import static org.hamcrest.Matchers.either;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import static org.hamcrest.Matchers.endsWith;
|
||||||
import ca.uhn.fhir.validation.ValidationResult;
|
import static org.junit.Assert.*;
|
||||||
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.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -21,8 +14,20 @@ import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import org.apache.commons.lang3.time.FastDateFormat;
|
||||||
import static org.junit.Assert.*;
|
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;
|
||||||
|
|
||||||
public class BaseDateTimeTypeDstu3Test {
|
public class BaseDateTimeTypeDstu3Test {
|
||||||
private static FhirContext ourCtx = FhirContext.forDstu3();
|
private static FhirContext ourCtx = FhirContext.forDstu3();
|
||||||
|
@ -453,7 +458,7 @@ public class BaseDateTimeTypeDstu3Test {
|
||||||
dt.setValueAsString("1974-12-25+10:00");
|
dt.setValueAsString("1974-12-25+10:00");
|
||||||
fail();
|
fail();
|
||||||
} catch (ca.uhn.fhir.parser.DataFormatException e) {
|
} catch (ca.uhn.fhir.parser.DataFormatException e) {
|
||||||
assertEquals("Invalid date/time format: \"1974-12-25+10:00\": Expected character 'T' at index 10 but found +", e.getMessage());
|
assertEquals("Invalid date/time format: \"1974-12-25+10:00\"", e.getMessage());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
DateTimeType dt = new DateTimeType();
|
DateTimeType dt = new DateTimeType();
|
||||||
|
@ -535,29 +540,6 @@ public class BaseDateTimeTypeDstu3Test {
|
||||||
dt.setValueAsString("201302");
|
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
|
@Test
|
||||||
public void testParseSecond() throws DataFormatException {
|
public void testParseSecond() throws DataFormatException {
|
||||||
DateTimeType dt = new DateTimeType();
|
DateTimeType dt = new DateTimeType();
|
||||||
|
@ -571,7 +553,7 @@ public class BaseDateTimeTypeDstu3Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseSecondZulu() throws DataFormatException {
|
public void testParseSecondulu() throws DataFormatException {
|
||||||
DateTimeType dt = new DateTimeType();
|
DateTimeType dt = new DateTimeType();
|
||||||
dt.setValueAsString("2013-02-03T11:22:33Z");
|
dt.setValueAsString("2013-02-03T11:22:33Z");
|
||||||
|
|
||||||
|
|
|
@ -343,7 +343,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
retVal = ourYearMonthDayTimeMilliFormat.parse(theValue);
|
retVal = ourYearMonthDayTimeMilliFormat.parse(theValue);
|
||||||
}
|
}
|
||||||
} catch (ParseException p2) {
|
} catch (ParseException p2) {
|
||||||
throw new IllegalArgumentException("Invalid date/time string (" + p2.getMessage() + "): " + theValue);
|
throw new IllegalArgumentException("Invalid data/time string (" + p2.getMessage() + "): " + theValue);
|
||||||
}
|
}
|
||||||
setTimeZone(theValue, hasMillis);
|
setTimeZone(theValue, hasMillis);
|
||||||
setPrecision(TemporalPrecisionEnum.MILLI);
|
setPrecision(TemporalPrecisionEnum.MILLI);
|
||||||
|
@ -357,7 +357,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
retVal = ourYearMonthDayTimeFormat.parse(theValue);
|
retVal = ourYearMonthDayTimeFormat.parse(theValue);
|
||||||
}
|
}
|
||||||
} catch (ParseException p2) {
|
} catch (ParseException p2) {
|
||||||
throw new IllegalArgumentException("Invalid date/time string (" + p2.getMessage() + "): " + theValue);
|
throw new IllegalArgumentException("Invalid data/time string (" + p2.getMessage() + "): " + theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeZone(theValue, hasMillis);
|
setTimeZone(theValue, hasMillis);
|
||||||
|
@ -372,7 +372,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
retVal = ourYearMonthDayTimeMinsFormat.parse(theValue);
|
retVal = ourYearMonthDayTimeMinsFormat.parse(theValue);
|
||||||
}
|
}
|
||||||
} catch (ParseException p2) {
|
} catch (ParseException p2) {
|
||||||
throw new IllegalArgumentException("Invalid date/time string (" + p2.getMessage() + "): " + theValue, p2);
|
throw new IllegalArgumentException("Invalid data/time string (" + p2.getMessage() + "): " + theValue, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeZone(theValue, hasMillis);
|
setTimeZone(theValue, hasMillis);
|
||||||
|
|
Loading…
Reference in New Issue