Class BaseDateTimeDt
- java.lang.Object
-
- ca.uhn.fhir.model.api.BaseElement
-
- ca.uhn.fhir.model.api.BaseIdentifiableElement
-
- ca.uhn.fhir.model.api.BasePrimitive<Date>
-
- ca.uhn.fhir.model.primitive.BaseDateTimeDt
-
- All Implemented Interfaces:
IDatatype,IElement,IIdentifiableElement,IPrimitiveDatatype<Date>,ISupportsUndeclaredExtensions,Externalizable,Serializable,IBase,IBaseDatatype,IPrimitiveType<Date>
- Direct Known Subclasses:
DateDt,DateParam.DateParamDateTimeHolder,DateTimeDt,InstantDt
public abstract class BaseDateTimeDt extends BasePrimitive<Date>
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringNOW_DATE_CONSTANT
-
Constructor Summary
Constructors Constructor Description BaseDateTimeDt()ConstructorBaseDateTimeDt(String theString)ConstructorBaseDateTimeDt(Date theDate, TemporalPrecisionEnum thePrecision)ConstructorBaseDateTimeDt(Date theDate, TemporalPrecisionEnum thePrecision, TimeZone theTimeZone)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Stringencode(Date theValue)Subclasses must override to convert a "coerced" value into an encoded one.IntegergetDay()Returns the month with 1-index, e.g.protected abstract 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 secondTemporalPrecisionEnumgetPrecision()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.protected abstract booleanisPrecisionAllowed(TemporalPrecisionEnum thePrecision)To be implemented by subclasses to indicate whether the given precision is allowed by this typebooleanisTimeZoneZulu()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" oneBaseDateTimeDtsetDay(int theDay)Sets the month with 1-index, e.g.BaseDateTimeDtsetHour(int theHour)Sets the hour of the day in a 24h clock, e.g.BaseDateTimeDtsetMillis(int theMillis)Sets the milliseconds within the current second.BaseDateTimeDtsetMinute(int theMinute)Sets the minute of the hour in the range 0-59BaseDateTimeDtsetMonth(int theMonth)Sets the month with 0-index, e.g.BaseDateTimeDtsetNanos(long theNanos)Sets the nanoseconds within the current secondBaseDateTimeDtsetPrecision(TemporalPrecisionEnum thePrecision)Sets the precision for this datatypeBaseDateTimeDtsetSecond(int theSecond)Sets the second of the minute in the range 0-59BaseDateTimeDtsetTimeZone(TimeZone theTimeZone)BaseDateTimeDtsetTimeZoneZulu(boolean theTimeZoneZulu)BaseDateTimeDtsetValue(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, 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)BaseDateTimeDtsetYear(int theYear)Sets the year, e.g.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 ca.uhn.fhir.model.api.BasePrimitive
equals, getValue, getValueAsString, hashCode, hasValue, isEmpty, readExternal, toString, updateStringValue, writeExternal
-
Methods inherited from class ca.uhn.fhir.model.api.BaseIdentifiableElement
getElementSpecificId, getId, setElementSpecificId, setId, setId
-
Methods inherited from class ca.uhn.fhir.model.api.BaseElement
addUndeclaredExtension, addUndeclaredExtension, addUndeclaredExtension, getAllUndeclaredExtensions, getFormatCommentsPost, getFormatCommentsPre, getUndeclaredExtensions, getUndeclaredExtensionsByUrl, getUndeclaredModifierExtensions, getUserData, hasFormatComment, isBaseEmpty, setUserData
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.hl7.fhir.instance.model.api.IBase
fhirType, getFormatCommentsPost, getFormatCommentsPre, getUserData, hasFormatComment, setUserData
-
-
-
-
Field Detail
-
NOW_DATE_CONSTANT
public static final String NOW_DATE_CONSTANT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseDateTimeDt
public BaseDateTimeDt()
Constructor
-
BaseDateTimeDt
public BaseDateTimeDt(Date theDate, TemporalPrecisionEnum thePrecision)
Constructor- Throws:
DataFormatException- If the specified precision is not allowed for this type
-
BaseDateTimeDt
public BaseDateTimeDt(Date theDate, TemporalPrecisionEnum thePrecision, TimeZone theTimeZone)
Constructor
-
BaseDateTimeDt
public BaseDateTimeDt(String theString)
Constructor- Throws:
DataFormatException- If the specified precision is not allowed for this type
-
-
Method Detail
-
encode
protected String encode(Date theValue)
Description copied from class:BasePrimitiveSubclasses must override to convert a "coerced" value into an encoded one.- Specified by:
encodein classBasePrimitive<Date>- Parameters:
theValue- Will not be null- Returns:
- May return null if the value does not correspond to anything
-
getDefaultPrecisionForDatatype
protected abstract 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 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
-
isPrecisionAllowed
protected abstract boolean isPrecisionAllowed(TemporalPrecisionEnum thePrecision)
To be implemented by subclasses to indicate whether the given precision is allowed by this type
-
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- ifBasePrimitive.getValue()returnsnull
-
parse
protected Date parse(String theValue) throws DataFormatException
Description copied from class:BasePrimitiveSubclasses must override to convert an encoded representation of this datatype into a "coerced" one- Specified by:
parsein classBasePrimitive<Date>- Parameters:
theValue- Will not be null- Returns:
- May return null if the value does not correspond to anything
- Throws:
DataFormatException
-
setDay
public BaseDateTimeDt setDay(int theDay)
Sets the month with 1-index, e.g. 1=the first day of the month
-
setHour
public BaseDateTimeDt setHour(int theHour)
Sets the hour of the day in a 24h clock, e.g. 13=1pm
-
setMillis
public BaseDateTimeDt 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 BaseDateTimeDt setMinute(int theMinute)
Sets the minute of the hour in the range 0-59
-
setMonth
public BaseDateTimeDt setMonth(int theMonth)
Sets the month with 0-index, e.g. 0=January
-
setNanos
public BaseDateTimeDt 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 BaseDateTimeDt setPrecision(TemporalPrecisionEnum thePrecision) throws DataFormatException
Sets the precision for this datatype- Throws:
DataFormatException
-
setSecond
public BaseDateTimeDt setSecond(int theSecond)
Sets the second of the minute in the range 0-59
-
setTimeZone
public BaseDateTimeDt setTimeZone(TimeZone theTimeZone)
-
setTimeZoneZulu
public BaseDateTimeDt setTimeZoneZulu(boolean theTimeZoneZulu)
-
setValue
public BaseDateTimeDt 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 interfaceIPrimitiveDatatype<Date>- Specified by:
setValuein interfaceIPrimitiveType<Date>- Overrides:
setValuein classBasePrimitive<Date>
-
setValue
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws 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:
DataFormatException
-
setValueAsString
public void setValueAsString(String theValue) throws DataFormatException
- Specified by:
setValueAsStringin interfaceIPrimitiveDatatype<Date>- Specified by:
setValueAsStringin interfaceIPrimitiveType<Date>- Overrides:
setValueAsStringin classBasePrimitive<Date>- Throws:
DataFormatException
-
setYear
public BaseDateTimeDt setYear(int theYear)
Sets the year, e.g. 2015
-
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.
-
-