Class BaseDateTimeType
- java.lang.Object
-
- org.hl7.fhir.r4.model.Base
-
- org.hl7.fhir.r4.model.Element
-
- org.hl7.fhir.r4.model.Type
-
- org.hl7.fhir.r4.model.PrimitiveType<Date>
-
- org.hl7.fhir.r4.model.BaseDateTimeType
-
- All Implemented Interfaces:
ca.uhn.fhir.model.api.IElement,Externalizable,Serializable,org.hl7.fhir.instance.model.api.IBase,org.hl7.fhir.instance.model.api.IBaseDatatype,org.hl7.fhir.instance.model.api.IBaseElement,org.hl7.fhir.instance.model.api.IBaseHasExtensions,org.hl7.fhir.instance.model.api.IPrimitiveType<Date>
- Direct Known Subclasses:
DateTimeType,DateType,InstantType
public abstract class BaseDateTimeType extends PrimitiveType<Date>
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BaseDateTimeType()ConstructorBaseDateTimeType(String theString)ConstructorBaseDateTimeType(Date theDate, ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision)ConstructorBaseDateTimeType(Date theDate, ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision, TimeZone theTimeZone)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(int theField, int theValue)Adds the given amount to the field specified by theFieldbooleanafter(DateTimeType theDateTimeType)Returnstrueif the given object represents a date/time beforethisobjectbooleanbefore(DateTimeType theDateTimeType)Returnstrueif the given object represents a date/time beforethisobjectBaseDateTimeTypedateTimeValue()protected Stringencode(Date theValue)Subclasses must override to convert a "coerced" value into an encoded one.BooleanequalsUsingFhirPathRules(BaseDateTimeType theOther)This method implements a datetime equality check using the rules as defined by FHIRPath.IntegergetDay()Returns the month with 1-index, e.g.protected abstract ca.uhn.fhir.model.api.TemporalPrecisionEnumgetDefaultPrecisionForDatatype()Returns the default precision for the given datatypeIntegergetHour()Returns the hour of the day in a 24h clock, e.g.IntegergetMillis()Returns the milliseconds within the current second.IntegergetMinute()Returns the minute of the hour in the range 0-59IntegergetMonth()Returns the month with 0-index, e.g.LonggetNanos()Returns the nanoseconds within the current secondca.uhn.fhir.model.api.TemporalPrecisionEnumgetPrecision()Gets the precision for this datatype (using the default for the given type if not set)IntegergetSecond()Returns the second of the minute in the range 0-59TimeZonegetTimeZone()Returns the TimeZone associated with this dateTime's value.GregorianCalendargetValueAsCalendar()Returns the value of this object as aGregorianCalendarIntegergetYear()Returns the year, e.g.booleanhasTime()booleanisDateTime()booleanisTimeZoneZulu()Returns true if the timezone is set to GMT-0:00 (Z)booleanisToday()Returnstrueif this object represents a date that is today's dateprotected Dateparse(String theValue)Subclasses must override to convert an encoded representation of this datatype into a "coerced" oneBaseDateTimeTypesetDay(int theDay)Sets the month with 1-index, e.g.BaseDateTimeTypesetHour(int theHour)Sets the hour of the day in a 24h clock, e.g.BaseDateTimeTypesetMillis(int theMillis)Sets the milliseconds within the current second.BaseDateTimeTypesetMinute(int theMinute)Sets the minute of the hour in the range 0-59BaseDateTimeTypesetMonth(int theMonth)Sets the month with 0-index, e.g.BaseDateTimeTypesetNanos(long theNanos)Sets the nanoseconds within the current secondvoidsetPrecision(ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision)Sets the precision for this datatypeBaseDateTimeTypesetSecond(int theSecond)Sets the second of the minute in the range 0-59BaseDateTimeTypesetTimeZone(TimeZone theTimeZone)BaseDateTimeTypesetTimeZoneZulu(boolean theTimeZoneZulu)BaseDateTimeTypesetValue(Date theValue)Sets the value for this type using the given Java Date object as the time, and using the default precision for this datatype (unless the precision is already set), as well as the local timezone as determined by the local operating system.voidsetValue(Date theValue, ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision)Sets the value for this type using the given Java Date object as the time, and using the specified precision, as well as the local timezone as determined by the local operating system.voidsetValueAsString(String theValue)protected voidsetValueAsV3String(String theV3String)BaseDateTimeTypesetYear(int theYear)Sets the year, e.g.CalendartoCalendar()Returns a view of this date/time as a Calendar object.StringtoHumanDisplay()Returns a human readable version of this date/time using the system local format.StringtoHumanDisplayLocalTimezone()Returns a human readable version of this date/time using the system local format, converted to the local timezone if neccesary.-
Methods inherited from class org.hl7.fhir.r4.model.PrimitiveType
asStringValue, copy, equalsDeep, equalsShallow, forceStringValue, fromStringValue, getProperty, getTypesForProperty, getValue, getValueAsString, hashCode, hasPrimitiveValue, hasValue, isEmpty, isPrimitive, makeProperty, primitiveValue, readExternal, setProperty, setProperty, toString, typedCopy, updateStringValue, writeExternal
-
Methods inherited from class org.hl7.fhir.r4.model.Element
addChild, addExtension, addExtension, addExtension, copyValues, fhirType, getExtension, getExtensionByUrl, getExtensionFirstRep, getExtensionsByUrl, getExtensionString, getId, getIdBase, getIdElement, getNamedProperty, hasExtension, hasExtension, hasId, hasIdElement, isDisallowExtensions, listChildren, noExtensions, removeExtension, setDisallowExtensions, setExtension, setId, setIdBase, setIdElement
-
Methods inherited from class org.hl7.fhir.r4.model.Base
castToAddress, castToAnnotation, castToAttachment, castToBase64Binary, castToBoolean, castToCanonical, castToCode, castToCodeableConcept, castToCoding, castToContactDetail, castToContactPoint, castToContributor, castToDataRequirement, castToDate, castToDateTime, castToDecimal, castToDosage, castToDuration, castToElementDefinition, castToExpression, castToExtension, castToHumanName, castToId, castToIdentifier, castToInstant, castToInteger, castToMarkdown, castToMarketingStatus, castToMeta, castToMoney, castToNarrative, castToOid, castToParameterDefinition, castToPeriod, castToPopulation, castToPositiveInt, castToProdCharacteristic, castToProductShelfLife, castToQuantity, castToRange, castToRatio, castToReference, castToRelatedArtifact, castToResource, castToSampledData, castToSignature, castToSimpleQuantity, castToString, castToSubstanceAmount, castToTime, castToTiming, castToTriggerDefinition, castToType, castToUnsignedInt, castToUri, castToUrl, castToUsageContext, castToXhtml, castToXhtmlString, children, clearUserData, compareDeep, compareDeep, compareDeep, compareDeep, compareValues, compareValues, equals, getChildByName, getFormatCommentsPost, getFormatCommentsPre, getNamedProperty, getUserData, getUserInt, getUserString, hasFormatComment, hasType, hasUserData, isBooleanPrimitive, isMetadataBased, isResource, listChildrenByName, listChildrenByName, setUserData, setUserDataINN
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.hl7.fhir.instance.model.api.IBase
fhirType, getFormatCommentsPost, getFormatCommentsPre, getUserData, hasFormatComment, setUserData
-
-
-
-
Constructor Detail
-
BaseDateTimeType
public BaseDateTimeType()
Constructor
-
BaseDateTimeType
public BaseDateTimeType(Date theDate, ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision)
Constructor- Throws:
IllegalArgumentException- If the specified precision is not allowed for this type
-
BaseDateTimeType
public BaseDateTimeType(Date theDate, ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision, TimeZone theTimeZone)
Constructor
-
BaseDateTimeType
public BaseDateTimeType(String theString)
Constructor- Throws:
IllegalArgumentException- If the specified precision is not allowed for this type
-
-
Method Detail
-
add
public void add(int theField, int theValue)
Adds the given amount to the field specified by theField- Parameters:
theField- The field, uses constants fromCalendarsuch asCalendar.YEARtheValue- The number to add (or subtract for a negative number)
-
after
public boolean after(DateTimeType theDateTimeType)
Returnstrueif the given object represents a date/time beforethisobject- Throws:
NullPointerException- Ifthis.getValue()ortheDateTimeType.getValue()returnnull
-
before
public boolean before(DateTimeType theDateTimeType)
Returnstrueif the given object represents a date/time beforethisobject- Throws:
NullPointerException- Ifthis.getValue()ortheDateTimeType.getValue()returnnull
-
encode
protected String encode(Date theValue)
Description copied from class:PrimitiveTypeSubclasses must override to convert a "coerced" value into an encoded one.- Specified by:
encodein classPrimitiveType<Date>- Parameters:
theValue- Will not be null- Returns:
- May return null if the value does not correspond to anything
-
getDefaultPrecisionForDatatype
protected abstract ca.uhn.fhir.model.api.TemporalPrecisionEnum getDefaultPrecisionForDatatype()
Returns the default precision for the given datatype
-
getMillis
public Integer getMillis()
Returns the milliseconds within the current second.Note that this method returns the same value as
getNanos()but with less precision.
-
getNanos
public Long getNanos()
Returns the nanoseconds within the current secondNote that this method returns the same value as
getMillis()but with more precision.
-
getPrecision
public ca.uhn.fhir.model.api.TemporalPrecisionEnum getPrecision()
Gets the precision for this datatype (using the default for the given type if not set)- See Also:
setPrecision(TemporalPrecisionEnum)
-
getTimeZone
public TimeZone getTimeZone()
Returns the TimeZone associated with this dateTime's value. May returnnullif no timezone was supplied.
-
getValueAsCalendar
public GregorianCalendar getValueAsCalendar()
Returns the value of this object as aGregorianCalendar
-
isTimeZoneZulu
public boolean isTimeZoneZulu()
Returns true if the timezone is set to GMT-0:00 (Z)
-
isToday
public boolean isToday()
Returnstrueif this object represents a date that is today's date- Throws:
NullPointerException- ifPrimitiveType.getValue()returnsnull
-
parse
protected Date parse(String theValue) throws ca.uhn.fhir.parser.DataFormatException
Description copied from class:PrimitiveTypeSubclasses must override to convert an encoded representation of this datatype into a "coerced" one- Specified by:
parsein classPrimitiveType<Date>- Parameters:
theValue- Will not be null- Returns:
- May return null if the value does not correspond to anything
- Throws:
ca.uhn.fhir.parser.DataFormatException
-
setDay
public BaseDateTimeType setDay(int theDay)
Sets the month with 1-index, e.g. 1=the first day of the month
-
setHour
public BaseDateTimeType setHour(int theHour)
Sets the hour of the day in a 24h clock, e.g. 13=1pm
-
setMillis
public BaseDateTimeType setMillis(int theMillis)
Sets the milliseconds within the current second.Note that this method sets the same value as
setNanos(long)but with less precision.
-
setMinute
public BaseDateTimeType setMinute(int theMinute)
Sets the minute of the hour in the range 0-59
-
setMonth
public BaseDateTimeType setMonth(int theMonth)
Sets the month with 0-index, e.g. 0=January
-
setNanos
public BaseDateTimeType setNanos(long theNanos)
Sets the nanoseconds within the current secondNote that this method sets the same value as
setMillis(int)but with more precision.
-
setPrecision
public void setPrecision(ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision) throws ca.uhn.fhir.parser.DataFormatException
Sets the precision for this datatype- Throws:
ca.uhn.fhir.parser.DataFormatException
-
setSecond
public BaseDateTimeType setSecond(int theSecond)
Sets the second of the minute in the range 0-59
-
setTimeZone
public BaseDateTimeType setTimeZone(TimeZone theTimeZone)
-
setTimeZoneZulu
public BaseDateTimeType setTimeZoneZulu(boolean theTimeZoneZulu)
-
setValue
public BaseDateTimeType setValue(Date theValue)
Sets the value for this type using the given Java Date object as the time, and using the default precision for this datatype (unless the precision is already set), as well as the local timezone as determined by the local operating system. Both of these properties may be modified in subsequent calls if neccesary.- Specified by:
setValuein interfaceorg.hl7.fhir.instance.model.api.IPrimitiveType<Date>- Overrides:
setValuein classPrimitiveType<Date>
-
setValue
public void setValue(Date theValue, ca.uhn.fhir.model.api.TemporalPrecisionEnum thePrecision) throws ca.uhn.fhir.parser.DataFormatException
Sets the value for this type using the given Java Date object as the time, and using the specified precision, as well as the local timezone as determined by the local operating system. Both of these properties may be modified in subsequent calls if neccesary.- Parameters:
theValue- The date valuethePrecision- The precision- Throws:
ca.uhn.fhir.parser.DataFormatException
-
setValueAsString
public void setValueAsString(String theValue) throws ca.uhn.fhir.parser.DataFormatException
- Specified by:
setValueAsStringin interfaceorg.hl7.fhir.instance.model.api.IPrimitiveType<Date>- Overrides:
setValueAsStringin classPrimitiveType<Date>- Throws:
ca.uhn.fhir.parser.DataFormatException
-
setValueAsV3String
protected void setValueAsV3String(String theV3String)
-
setYear
public BaseDateTimeType setYear(int theYear)
Sets the year, e.g. 2015
-
toCalendar
public Calendar toCalendar()
Returns a view of this date/time as a Calendar object. Note that the returned Calendar object is entirely independent fromthisobject. Changes to the calendar will not affectthis.
-
toHumanDisplay
public String toHumanDisplay()
Returns a human readable version of this date/time using the system local format.Note on time zones: This method renders the value using the time zone that is contained within the value. For example, if this date object contains the value "2012-01-05T12:00:00-08:00", the human display will be rendered as "12:00:00" even if the application is being executed on a system in a different time zone. If this behaviour is not what you want, use
toHumanDisplayLocalTimezone()instead.
-
toHumanDisplayLocalTimezone
public String toHumanDisplayLocalTimezone()
Returns a human readable version of this date/time using the system local format, converted to the local timezone if neccesary.
-
isDateTime
public boolean isDateTime()
- Overrides:
isDateTimein classBase
-
dateTimeValue
public BaseDateTimeType dateTimeValue()
- Overrides:
dateTimeValuein classBase
-
hasTime
public boolean hasTime()
-
equalsUsingFhirPathRules
public Boolean equalsUsingFhirPathRules(BaseDateTimeType theOther)
This method implements a datetime equality check using the rules as defined by FHIRPath. This method returns:- true if the given datetimes represent the exact same instant with the same precision (irrespective of the timezone)
- true if the given datetimes represent the exact same instant but one includes milliseconds of
.[0]+while the other includes only SECONDS precision (irrespecitve of the timezone) - true if the given datetimes represent the exact same year/year-month/year-month-date (if both operands have the same precision)
- false if both datetimes have equal precision of MINUTE or greater, one has no timezone specified but the other does, and could not represent the same instant in any timezone
- null if both datetimes have equal precision of MINUTE or greater, one has no timezone specified but the other does, and could potentially represent the same instant in any timezone
- false if the given datetimes have the same precision but do not represent the same instant (irrespective of timezone)
- null otherwise (since these datetimes are not comparable)
-
-