org.joda.time

Interface ReadableInstant

All Superinterfaces:
Comparable
Known Subinterfaces:
ReadableDateTime, ReadWritableDateTime, ReadWritableInstant
Known Implementing Classes:
AbstractDateTime, AbstractInstant, BaseDateTime, DateMidnight, DateTime, Instant, MutableDateTime

public interface ReadableInstant
extends Comparable

Defines an instant in the datetime continuum. This interface expresses the datetime as milliseconds from 1970-01-01T00:00:00Z.

The implementation of this interface may be mutable or immutable. This interface only gives access to retrieve data, never to change it.

Methods in your application should be defined using ReadableInstant as a parameter if the method only wants to read the instant without needing to know the specific datetime fields.

Author:
Stephen Colebourne
Since:
1.0

Method Summary

int
compareTo(Object readableInstant)
Compares this object with the specified object for ascending millisecond instant order.
boolean
equals(Object readableInstant)
Compares this object with the specified object for equality based on the millisecond instant and the Chronology.
int
get(DateTimeFieldType type)
Get the value of one of the fields of a datetime.
Chronology
getChronology()
Gets the chronology of the instant.
long
getMillis()
Get the value as the number of milliseconds since the epoch, 1970-01-01T00:00:00Z.
DateTimeZone
getZone()
Gets the time zone of the instant from the chronology.
int
hashCode()
Gets a hash code for the instant that is compatible with the equals method.
boolean
isAfter(ReadableInstant instant)
Is this instant after the instant passed in comparing solely by millisecond.
boolean
isBefore(ReadableInstant instant)
Is this instant before the 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
isSupported(DateTimeFieldType field)
Checks whether the field type specified is supported by this implementation.
Instant
toInstant()
Get the value as a simple immutable Instant object.
String
toString()
Get the value as a String in a recognisable ISO8601 format.

Method Details

compareTo

public int compareTo(Object readableInstant)
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.

Parameters:
readableInstant - a readable instant to check against
Returns:
negative value if this is less, 0 if equal, or positive value if greater

equals

public boolean equals(Object readableInstant)
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

get

public int get(DateTimeFieldType type)
Get the value of one of the fields of a datetime.

This method uses the chronology of the instant to obtain the value.

Parameters:
type - a field type, usually obtained from DateTimeFieldType, not null
Returns:
the value of that field

getChronology

public Chronology getChronology()
Gets the chronology of the instant.

The Chronology provides conversion from the millisecond value to meaningful fields in a particular calendar system.

Returns:
the Chronology, never null

getMillis

public long getMillis()
Get the value as the number of milliseconds since the epoch, 1970-01-01T00:00:00Z.
Returns:
the value as milliseconds

getZone

public DateTimeZone getZone()
Gets the time zone of the instant from the chronology.
Returns:
the DateTimeZone that the instant is using, never null

hashCode

public int hashCode()
Gets a hash code for the instant that is compatible with the equals method.

The formula used must be as follows:

 ((int) (getMillis() ^ (getMillis() >>> 32))) +
 (getChronology().hashCode())
 
Returns:
a hash code as defined above

isAfter

public boolean isAfter(ReadableInstant instant)
Is this instant after the instant passed in comparing solely by millisecond.
Parameters:
instant - an instant to check against, null means now
Returns:
true if the instant is after the instant passed in

isBefore

public boolean isBefore(ReadableInstant instant)
Is this instant before the instant passed in comparing solely by millisecond.
Parameters:
instant - an instant to check against, null means now
Returns:
true if the instant is before the instant passed in

isEqual

public boolean isEqual(ReadableInstant instant)
Is this instant equal to the instant passed in comparing solely by millisecond.
Parameters:
instant - an instant to check against, null means now
Returns:
true if the instant is equal to the instant passed in

isSupported

public boolean isSupported(DateTimeFieldType field)
Checks whether the field type specified is supported by this implementation.
Parameters:
field - the field type to check, may be null which returns false
Returns:
true if the field is supported

toInstant

public Instant toInstant()
Get the value as a simple immutable Instant object.

This can be useful if you don't trust the implementation of the interface to be well-behaved, or to get a guaranteed immutable object.

Returns:
the value as an Instant object

toString

public String toString()
Get the value as a String in a recognisable ISO8601 format.

The string output is in ISO8601 format to enable the String constructor to correctly parse it.

Returns:
the value as an ISO8601 string

Copyright (c) 2001-2006 - Joda.org