Improve multithreaded performance of datetime types
This commit is contained in:
parent
36fa3a97af
commit
1922f549bb
|
@ -1,33 +1,33 @@
|
||||||
package org.hl7.fhir.dstu2.model;
|
package org.hl7.fhir.dstu2.model;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
|
@ -39,6 +39,7 @@ import org.hl7.fhir.utilities.DateTimeUtil;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.*;
|
import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.*;
|
||||||
|
@ -74,6 +75,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
|
|
||||||
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
||||||
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
||||||
|
private static final Map<String, TimeZone> timezoneCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ArrayList<FastDateFormat> formatters = new ArrayList<FastDateFormat>();
|
ArrayList<FastDateFormat> formatters = new ArrayList<FastDateFormat>();
|
||||||
|
@ -159,7 +161,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
return ourYearFormat.format(theValue);
|
return ourYearFormat.format(theValue);
|
||||||
case MINUTE:
|
case MINUTE:
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
GregorianCalendar cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
cal.setTime(theValue);
|
cal.setTime(theValue);
|
||||||
return ourYearMonthDayTimeMinsFormat.format(cal) + "Z";
|
return ourYearMonthDayTimeMinsFormat.format(cal) + "Z";
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
|
@ -171,7 +173,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
}
|
}
|
||||||
case SECOND:
|
case SECOND:
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
GregorianCalendar cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
cal.setTime(theValue);
|
cal.setTime(theValue);
|
||||||
return ourYearMonthDayTimeFormat.format(cal) + "Z";
|
return ourYearMonthDayTimeFormat.format(cal) + "Z";
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
|
@ -183,7 +185,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
}
|
}
|
||||||
case MILLI:
|
case MILLI:
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
GregorianCalendar cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
cal.setTime(theValue);
|
cal.setTime(theValue);
|
||||||
return ourYearMonthDayTimeMilliFormat.format(cal) + "Z";
|
return ourYearMonthDayTimeMilliFormat.format(cal) + "Z";
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
|
@ -410,9 +412,9 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
if (theValueString.endsWith("Z")) {
|
if (theValueString.endsWith("Z")) {
|
||||||
setTimeZoneZulu(true);
|
setTimeZoneZulu(true);
|
||||||
} else if (theValueString.indexOf("GMT", timeZoneStart) != -1) {
|
} else if (theValueString.indexOf("GMT", timeZoneStart) != -1) {
|
||||||
setTimeZone(TimeZone.getTimeZone(theValueString.substring(timeZoneStart)));
|
setTimeZone(getTimeZone(theValueString.substring(timeZoneStart)));
|
||||||
} else if (theValueString.indexOf('+', timeZoneStart) != -1 || theValueString.indexOf('-', timeZoneStart) != -1) {
|
} else if (theValueString.indexOf('+', timeZoneStart) != -1 || theValueString.indexOf('-', timeZoneStart) != -1) {
|
||||||
setTimeZone(TimeZone.getTimeZone("GMT" + theValueString.substring(timeZoneStart)));
|
setTimeZone(getTimeZone("GMT" + theValueString.substring(timeZoneStart)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,9 +530,9 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
int hours = offsetAbs / 60;
|
int hours = offsetAbs / 60;
|
||||||
|
|
||||||
if (theZoneOffsetMinutes < 0) {
|
if (theZoneOffsetMinutes < 0) {
|
||||||
setTimeZone(TimeZone.getTimeZone("GMT-" + hours + ":" + mins));
|
setTimeZone(getTimeZone("GMT-" + hours + ":" + mins));
|
||||||
} else {
|
} else {
|
||||||
setTimeZone(TimeZone.getTimeZone("GMT+" + hours + ":" + mins));
|
setTimeZone(getTimeZone("GMT+" + hours + ":" + mins));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,4 +620,9 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeZone getTimeZone(String offset) {
|
||||||
|
return timezoneCache.computeIfAbsent(offset, (offsetLocal) ->
|
||||||
|
TimeZone.getTimeZone("GMT" + offsetLocal));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package org.hl7.fhir.dstu2016may.model;
|
package org.hl7.fhir.dstu2016may.model;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
@ -35,7 +35,9 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -52,6 +54,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
|
|
||||||
static final long NANOS_PER_MILLIS = 1000000L;
|
static final long NANOS_PER_MILLIS = 1000000L;
|
||||||
static final long NANOS_PER_SECOND = 1000000000L;
|
static final long NANOS_PER_SECOND = 1000000000L;
|
||||||
|
private static final Map<String, TimeZone> timezoneCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
||||||
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
||||||
|
@ -114,7 +117,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
} else {
|
} else {
|
||||||
GregorianCalendar cal;
|
GregorianCalendar cal;
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
cal = new GregorianCalendar(myTimeZone);
|
cal = new GregorianCalendar(myTimeZone);
|
||||||
} else {
|
} else {
|
||||||
|
@ -209,7 +212,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
*/
|
*/
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
return TimeZone.getTimeZone("GMT");
|
return getTimeZone("GMT");
|
||||||
}
|
}
|
||||||
return myTimeZone;
|
return myTimeZone;
|
||||||
}
|
}
|
||||||
|
@ -414,7 +417,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
||||||
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
||||||
myTimeZoneZulu = false;
|
myTimeZoneZulu = false;
|
||||||
myTimeZone = TimeZone.getTimeZone("GMT" + theValue);
|
myTimeZone = getTimeZone("GMT" + theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -750,4 +753,9 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeZone getTimeZone(String offset) {
|
||||||
|
return timezoneCache.computeIfAbsent(offset, (offsetLocal) ->
|
||||||
|
TimeZone.getTimeZone("GMT" + offsetLocal));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package org.hl7.fhir.dstu3.model;
|
package org.hl7.fhir.dstu3.model;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
@ -35,7 +35,9 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
@ -51,6 +53,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
static final long NANOS_PER_MILLIS = 1000000L;
|
static final long NANOS_PER_MILLIS = 1000000L;
|
||||||
|
|
||||||
static final long NANOS_PER_SECOND = 1000000000L;
|
static final long NANOS_PER_SECOND = 1000000000L;
|
||||||
|
private static final Map<String, TimeZone> timezoneCache = new ConcurrentHashMap<>();
|
||||||
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
||||||
|
|
||||||
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
||||||
|
@ -171,7 +174,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
} else {
|
} else {
|
||||||
GregorianCalendar cal;
|
GregorianCalendar cal;
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
cal = new GregorianCalendar(myTimeZone);
|
cal = new GregorianCalendar(myTimeZone);
|
||||||
} else {
|
} else {
|
||||||
|
@ -336,7 +339,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
*/
|
*/
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
return TimeZone.getTimeZone("GMT");
|
return getTimeZone("GMT");
|
||||||
}
|
}
|
||||||
return myTimeZone;
|
return myTimeZone;
|
||||||
}
|
}
|
||||||
|
@ -646,7 +649,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
||||||
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
||||||
myTimeZoneZulu = false;
|
myTimeZoneZulu = false;
|
||||||
myTimeZone = TimeZone.getTimeZone("GMT" + theValue);
|
myTimeZone = getTimeZone("GMT" + theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -841,4 +844,9 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeZone getTimeZone(String offset) {
|
||||||
|
return timezoneCache.computeIfAbsent(offset, (offsetLocal) ->
|
||||||
|
TimeZone.getTimeZone("GMT" + offsetLocal));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package org.hl7.fhir.r4.model;
|
package org.hl7.fhir.r4.model;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
@ -35,7 +35,9 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -51,6 +53,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
static final long NANOS_PER_MILLIS = 1000000L;
|
static final long NANOS_PER_MILLIS = 1000000L;
|
||||||
|
|
||||||
static final long NANOS_PER_SECOND = 1000000000L;
|
static final long NANOS_PER_SECOND = 1000000000L;
|
||||||
|
private static final Map<String, TimeZone> timezoneCache = new ConcurrentHashMap<>();
|
||||||
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
||||||
|
|
||||||
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
||||||
|
@ -174,7 +177,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
} else {
|
} else {
|
||||||
GregorianCalendar cal;
|
GregorianCalendar cal;
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
cal = new GregorianCalendar(myTimeZone);
|
cal = new GregorianCalendar(myTimeZone);
|
||||||
} else {
|
} else {
|
||||||
|
@ -339,7 +342,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
*/
|
*/
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
return TimeZone.getTimeZone("GMT");
|
return getTimeZone("GMT");
|
||||||
}
|
}
|
||||||
return myTimeZone;
|
return myTimeZone;
|
||||||
}
|
}
|
||||||
|
@ -645,7 +648,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
||||||
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
||||||
myTimeZoneZulu = false;
|
myTimeZoneZulu = false;
|
||||||
myTimeZone = TimeZone.getTimeZone("GMT" + theValue);
|
myTimeZone = getTimeZone("GMT" + theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -943,5 +946,10 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
public String fpValue() {
|
public String fpValue() {
|
||||||
return "@"+primitiveValue();
|
return "@"+primitiveValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeZone getTimeZone(String offset) {
|
||||||
|
return timezoneCache.computeIfAbsent(offset, (offsetLocal) ->
|
||||||
|
TimeZone.getTimeZone("GMT" + offsetLocal));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package org.hl7.fhir.r5.model;
|
package org.hl7.fhir.r5.model;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||||
|
@ -42,7 +42,9 @@ import org.hl7.fhir.utilities.Utilities;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
static final long NANOS_PER_MILLIS = 1000000L;
|
static final long NANOS_PER_MILLIS = 1000000L;
|
||||||
|
|
||||||
static final long NANOS_PER_SECOND = 1000000000L;
|
static final long NANOS_PER_SECOND = 1000000000L;
|
||||||
|
private static final Map<String, TimeZone> timezoneCache = new ConcurrentHashMap<>();
|
||||||
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateFormat = FastDateFormat.getDateInstance(FastDateFormat.MEDIUM);
|
||||||
|
|
||||||
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
private static final FastDateFormat ourHumanDateTimeFormat = FastDateFormat.getDateTimeInstance(FastDateFormat.MEDIUM, FastDateFormat.MEDIUM);
|
||||||
|
@ -174,7 +177,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
} else {
|
} else {
|
||||||
GregorianCalendar cal;
|
GregorianCalendar cal;
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
cal = new GregorianCalendar(getTimeZone("GMT"));
|
||||||
} else if (myTimeZone != null) {
|
} else if (myTimeZone != null) {
|
||||||
cal = new GregorianCalendar(myTimeZone);
|
cal = new GregorianCalendar(myTimeZone);
|
||||||
} else {
|
} else {
|
||||||
|
@ -346,7 +349,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
*/
|
*/
|
||||||
public TimeZone getTimeZone() {
|
public TimeZone getTimeZone() {
|
||||||
if (myTimeZoneZulu) {
|
if (myTimeZoneZulu) {
|
||||||
return TimeZone.getTimeZone("GMT");
|
return getTimeZone("GMT");
|
||||||
}
|
}
|
||||||
return myTimeZone;
|
return myTimeZone;
|
||||||
}
|
}
|
||||||
|
@ -652,7 +655,7 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
|
||||||
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
|
||||||
myTimeZoneZulu = false;
|
myTimeZoneZulu = false;
|
||||||
myTimeZone = TimeZone.getTimeZone("GMT" + theValue);
|
myTimeZone = getTimeZone("GMT" + theValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -1011,4 +1014,9 @@ public abstract class BaseDateTimeType extends PrimitiveType<Date> {
|
||||||
return "@"+primitiveValue();
|
return "@"+primitiveValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TimeZone getTimeZone(String offset) {
|
||||||
|
return timezoneCache.computeIfAbsent(offset, (offsetLocal) ->
|
||||||
|
TimeZone.getTimeZone("GMT" + offsetLocal));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue