diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java index 20ff7d0bf4e..ed1f69379f0 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/DateRangeParam.java @@ -357,6 +357,13 @@ public class DateRangeParam implements IQueryParameterAnd { throw new InvalidRequestException("DateRange parameter does not suppport OR queries"); } String param = paramList.get(0); + + /* + * Since ' ' is escaped as '+' we'll be nice to anyone might have accidentally not + * escaped theirs + */ + param = param.replace(' ', '+'); + DateParam parsed = new DateParam(); parsed.setValueAsQueryToken(paramList.getQualifier(), param); addParam(parsed); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java index b3bc1bb37c3..99290abbc4d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.TimeZone; import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.IdType; @@ -183,6 +184,44 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { } + @Test + public void testUpdateConditionalByLastUpdatedWithWrongTimezone() throws Exception { + TimeZone def = TimeZone.getDefault(); + try { + TimeZone.setDefault(TimeZone.getTimeZone("GMT-0:00")); + String methodName = "testUpdateByUrl"; + + Patient p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName + "2"); + myPatientDao.create(p, mySrd).getId(); + + InstantDt start = InstantDt.withCurrentTime(); + Thread.sleep(100); + + p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + IIdType id = myPatientDao.create(p, mySrd).getId(); + ourLog.info("Created patient, got it: {}", id); + + Thread.sleep(100); + + p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.addName().addFamily("Hello"); + p.setId("Patient/" + methodName); + + myPatientDao.update(p, "Patient?_lastUpdated=gt" + start.getValueAsString(), mySrd); + + p = myPatientDao.read(id.toVersionless(), mySrd); + assertThat(p.getIdElement().toVersionless().toString(), not(containsString("test"))); + assertEquals(id.toVersionless(), p.getIdElement().toVersionless()); + assertNotEquals(id, p.getIdElement()); + assertThat(p.getIdElement().toString(), endsWith("/_history/2")); + } finally { + TimeZone.setDefault(def); + } + } + @Test public void testUpdateCreatesTextualIdIfItDoesntAlreadyExist() { Patient p = new Patient(); 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 323b6554c3c..c80ff38c7dc 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 @@ -49,6 +49,16 @@ public class BaseDateTimeDtDstu2Test { myDateInstantZoneParser = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("GMT-02:00")); } + @Test + public void testEncodeZeroOffset() { + DateTimeDt dt = new DateTimeDt(); + dt.setValueAsString("2011-01-01T12:00:00"); + dt.setTimeZone(TimeZone.getTimeZone("GMT-0:00")); + + String val = dt.getValueAsString(); + assertEquals("2011-01-01T18:00:00+00:00", val); + } + @Test public void setTimezoneToZulu() {