Class AbstractInstant
- All Implemented Interfaces:
Comparable<ReadableInstant>
,ReadableInstant
- Direct Known Subclasses:
AbstractDateTime
,Instant
This class has no concept of a chronology, all methods work on the millisecond instant.
This class should generally not be used directly by API users. The
ReadableInstant
interface should be used when different
kinds of date/time objects are to be referenced.
Whenever you want to implement ReadableInstant
you should
extend this class.
AbstractInstant itself is thread-safe and immutable, but subclasses may be mutable and not thread-safe.
- Since:
- 1.0
- Author:
- Stephen Colebourne, Brian S O'Neill
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(ReadableInstant other) Compares this object with the specified object for ascending millisecond instant order.boolean
Compares this object with the specified object for equality based on the millisecond instant, chronology and time zone.int
get
(DateTimeField field) Get the value of one of the fields of a datetime.int
get
(DateTimeFieldType type) Get the value of one of the fields of a datetime using the chronology of the instant.getZone()
Gets the time zone of the instant from the chronology.int
hashCode()
Gets a hash code for the instant as defined inReadableInstant
.boolean
isAfter
(long instant) Is this instant strictly after the millisecond instant passed in comparing solely by millisecond.boolean
isAfter
(ReadableInstant instant) Is this instant strictly after the instant passed in comparing solely by millisecond.boolean
Is this instant strictly after the current instant comparing solely by millisecond.boolean
isBefore
(long instant) Is this instant strictly before the millisecond instant passed in comparing solely by millisecond.boolean
isBefore
(ReadableInstant instant) Is this instant strictly before the instant passed in comparing solely by millisecond.boolean
Is this instant strictly before the current instant comparing solely by millisecond.boolean
isEqual
(long instant) Is this instant equal to the millisecond instant passed in comparing solely by millisecond.boolean
isEqual
(ReadableInstant instant) Is this instant equal to the instant passed in comparing solely by millisecond.boolean
Is this instant equal to the current instant comparing solely by millisecond.boolean
isSupported
(DateTimeFieldType type) Checks if the field type specified is supported by this instant and chronology.toDate()
Get the date time as ajava.util.Date
.Get this object as a DateTime in the same zone.toDateTime
(Chronology chronology) Get this object as a DateTime using the given chronology and its zone.toDateTime
(DateTimeZone zone) Get this object as a DateTime using the same chronology but a different zone.Get this object as a DateTime using ISOChronology in the same zone.Get this object as an Instant.Get this object as a MutableDateTime in the same zone.toMutableDateTime
(Chronology chronology) Get this object as a MutableDateTime using the given chronology and its zone.Get this object as a MutableDateTime using the same chronology but a different zone.Get this object as a MutableDateTime using ISOChronology in the same zone.toString()
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).toString
(DateTimeFormatter formatter) Uses the specified formatter to convert this partial to a String.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.joda.time.ReadableInstant
getChronology, getMillis
-
Constructor Details
-
AbstractInstant
protected AbstractInstant()Constructor.
-
-
Method Details
-
getZone
Gets the time zone of the instant from the chronology.- Specified by:
getZone
in interfaceReadableInstant
- Returns:
- the DateTimeZone that the instant is using, never null
-
get
Get the value of one of the fields of a datetime using the chronology of the instant.This method uses the chronology of the instant to obtain the value. For example:
DateTime dt = new DateTime(); int year = dt.get(DateTimeFieldType.year());
- Specified by:
get
in interfaceReadableInstant
- Parameters:
type
- a field type, usually obtained from DateTimeFieldType, not null- Returns:
- the value of that field
- Throws:
IllegalArgumentException
- if the field type is null
-
isSupported
Checks if the field type specified is supported by this instant and chronology. This can be used to avoid exceptions inget(DateTimeFieldType)
.- Specified by:
isSupported
in interfaceReadableInstant
- Parameters:
type
- a field type, usually obtained from DateTimeFieldType- Returns:
- true if the field type is supported
-
get
Get the value of one of the fields of a datetime.This could be used to get a field using a different Chronology. For example:
Instant dt = new Instant(); int gjYear = dt.get(Chronology.getCoptic().year());
- Parameters:
field
- the DateTimeField to use, not null- Returns:
- the value
- Throws:
IllegalArgumentException
- if the field is null
-
toInstant
Get this object as an Instant.- Specified by:
toInstant
in interfaceReadableInstant
- Returns:
- an Instant using the same millis
-
toDateTime
Get this object as a DateTime in the same zone.- Returns:
- a DateTime using the same millis
-
toDateTimeISO
Get this object as a DateTime using ISOChronology in the same zone.- Returns:
- a DateTime using the same millis with ISOChronology
-
toDateTime
Get this object as a DateTime using the same chronology but a different zone.- Parameters:
zone
- time zone to apply, or default if null- Returns:
- a DateTime using the same millis
-
toDateTime
Get this object as a DateTime using the given chronology and its zone.- Parameters:
chronology
- chronology to apply, or ISOChronology if null- Returns:
- a DateTime using the same millis
-
toMutableDateTime
Get this object as a MutableDateTime in the same zone.- Returns:
- a MutableDateTime using the same millis
-
toMutableDateTimeISO
Get this object as a MutableDateTime using ISOChronology in the same zone.- Returns:
- a MutableDateTime using the same millis with ISOChronology
-
toMutableDateTime
Get this object as a MutableDateTime using the same chronology but a different zone.- Parameters:
zone
- time zone to apply, or default if null- Returns:
- a MutableDateTime using the same millis
-
toMutableDateTime
Get this object as a MutableDateTime using the given chronology and its zone.- Parameters:
chronology
- chronology to apply, or ISOChronology if null- Returns:
- a MutableDateTime using the same millis
-
toDate
Get the date time as ajava.util.Date
.The
Date
object created has exactly the same millisecond instant as this object.- Returns:
- a Date initialised with this datetime
-
equals
Compares this object with the specified object for equality based on the millisecond instant, chronology and time zone.Two objects which represent the same instant in time, but are in different time zones (based on time zone id), will be considered to be different. Only two objects with the same
DateTimeZone
,Chronology
and instant are equal.See
isEqual(ReadableInstant)
for an equals method that ignores the Chronology and time zone.All ReadableInstant instances are accepted.
- Specified by:
equals
in interfaceReadableInstant
- Overrides:
equals
in classObject
- Parameters:
readableInstant
- a readable instant to check against- Returns:
- true if millisecond and chronology are equal, false if not or the instant is null or of an incorrect type
-
hashCode
public int hashCode()Gets a hash code for the instant as defined inReadableInstant
.- Specified by:
hashCode
in interfaceReadableInstant
- Overrides:
hashCode
in classObject
- Returns:
- a suitable hash code
-
compareTo
Compares this object with the specified object for ascending millisecond instant order. This ordering is inconsistent with equals, as it ignores the Chronology.All ReadableInstant instances are accepted.
- Specified by:
compareTo
in interfaceComparable<ReadableInstant>
- Parameters:
other
- a readable instant to check against- Returns:
- negative value if this is less, 0 if equal, or positive value if greater
- Throws:
NullPointerException
- if the object is nullClassCastException
- if the object type is not supported
-
isAfter
public boolean isAfter(long instant) Is this instant strictly after the millisecond instant passed in comparing solely by millisecond.- Parameters:
instant
- a millisecond instant to check against- Returns:
- true if this instant is strictly after the instant passed in
-
isAfterNow
public boolean isAfterNow()Is this instant strictly after the current instant comparing solely by millisecond.- Returns:
- true if this instant is strictly after the current instant
-
isAfter
Is this instant strictly after the instant passed in comparing solely by millisecond.- Specified by:
isAfter
in interfaceReadableInstant
- Parameters:
instant
- an instant to check against, null means now- Returns:
- true if the instant is strictly after the instant passed in
-
isBefore
public boolean isBefore(long instant) Is this instant strictly before the millisecond instant passed in comparing solely by millisecond.- Parameters:
instant
- a millisecond instant to check against- Returns:
- true if this instant is strictly before the instant passed in
-
isBeforeNow
public boolean isBeforeNow()Is this instant strictly before the current instant comparing solely by millisecond.- Returns:
- true if this instant is strictly before the current instant
-
isBefore
Is this instant strictly before the instant passed in comparing solely by millisecond.- Specified by:
isBefore
in interfaceReadableInstant
- Parameters:
instant
- an instant to check against, null means now- Returns:
- true if the instant is strictly before the instant passed in
-
isEqual
public boolean isEqual(long instant) Is this instant equal to the millisecond instant passed in comparing solely by millisecond.- Parameters:
instant
- a millisecond instant to check against- Returns:
- true if this instant is equal to the instant passed in
-
isEqualNow
public boolean isEqualNow()Is this instant equal to the current instant comparing solely by millisecond.- Returns:
- true if this instant is equal to the current instant
-
isEqual
Is this instant equal to the instant passed in comparing solely by millisecond.- Specified by:
isEqual
in interfaceReadableInstant
- Parameters:
instant
- an instant to check against, null means now- Returns:
- true if the instant is equal to the instant passed in
-
toString
Output the date time in ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZZ).- Specified by:
toString
in interfaceReadableInstant
- Overrides:
toString
in classObject
- Returns:
- ISO8601 time formatted string, not null
-
toString
Uses the specified formatter to convert this partial to a String.- Parameters:
formatter
- the formatter to use, null means usetoString()
.- Returns:
- the formatted string, not null
- Since:
- 1.1
-