Package com.globalmentor.iso.datetime
Class AbstractISODateTime
- java.lang.Object
-
- java.util.Date
-
- com.globalmentor.time.Time
-
- com.globalmentor.iso.datetime.AbstractISODateTime
-
- All Implemented Interfaces:
ISOTemporal
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<java.util.Date>
- Direct Known Subclasses:
ISODate
,ISODateTime
public abstract class AbstractISODateTime extends Time implements ISOTemporal
The abstract base type for ISO date and date time types. If there is no explicit UTC offset (i.e. this is a floating value), the time is stored internally in terms of UTC.- Author:
- Garret Wilson
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.globalmentor.time.Time
Time.Resolution
-
-
Field Summary
-
Fields inherited from class com.globalmentor.time.Time
HOURS_PER_DAY, MILLISECONDS_PER_SECOND, MINUTES_PER_HOUR, SECONDS_PER_MINUTE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractISODateTime(ISOTemporalComponents temporalComponents, boolean useTime)
Temporal components constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringBuilder
append(java.lang.StringBuilder stringBuilder)
Appends the canonical lexical representation of this date time to a string builder in the form "YYYY-MM-DDThh:mm:ss[.s+]+/-hh:mm".int
getDay()
ISOTime
getISOTime()
int
getMonth()
int
getYear()
java.util.GregorianCalendar
toCalendar()
Returns a calendar representing this date and time for the default locale.java.util.GregorianCalendar
toCalendar(java.util.Locale locale)
Returns a calendar representing this date and time.abstract java.util.Date
toDate(java.util.TimeZone timeZone)
Returns a date that represents this temporal information in the given time zone.abstract ISODate
toISODate()
Returns the date portion of this date and time.java.lang.String
toString()
Returns the canonical lexical representation of this date time in the form "YYYY-MM-DDThh:mm:ss[.s+]+/-hh:mm".static AbstractISODateTime
valueOfLenient(java.lang.String string)
Returns an ISO date or date time object holding the value of the specified string.static AbstractISODateTime
valueOfLiberal(java.lang.String string)
Returns an ISO date or date time object holding the value of the specified string.
-
-
-
Constructor Detail
-
AbstractISODateTime
protected AbstractISODateTime(ISOTemporalComponents temporalComponents, boolean useTime)
Temporal components constructor.- Parameters:
temporalComponents
- The components of the time information.useTime
-true
if the time should be used, orfalse
if the given type components should be ignored.- Throws:
java.lang.NullPointerException
- if the temporal components is null.
-
-
Method Detail
-
getYear
public final int getYear()
- Overrides:
getYear
in classjava.util.Date
- Returns:
- The year, 0-9999.
-
getMonth
public final int getMonth()
- Overrides:
getMonth
in classjava.util.Date
- Returns:
- The month, 1-12.
-
getDay
public final int getDay()
- Overrides:
getDay
in classjava.util.Date
- Returns:
- The day, 1-31.
-
getISOTime
public ISOTime getISOTime()
- Returns:
- The time, or
null
if there is a date with no time (not even midnight)
-
append
public java.lang.StringBuilder append(java.lang.StringBuilder stringBuilder)
Appends the canonical lexical representation of this date time to a string builder in the form "YYYY-MM-DDThh:mm:ss[.s+]+/-hh:mm".- Specified by:
append
in interfaceISOTemporal
- Parameters:
stringBuilder
- The string builder to which the lexical representation will be appended.- Returns:
- The string builder.
-
valueOfLenient
public static AbstractISODateTime valueOfLenient(java.lang.String string) throws ArgumentSyntaxException
Returns an ISO date or date time object holding the value of the specified string.Lenient parsing makes the following allowances:
- Seconds are considered optional.
- Whitespace before and after the date/time is allowed.
- The looser RFC 3339 Internet timestamp format is allowed, allowing the UTC designator, 90, for example.
- If time is present, an
ISODateTime
is returned; otherwise, anISODate
is returned.
- Parameters:
string
- The string to be parsed as a date time.- Returns:
- An ISO date time object represented by the string.
- Throws:
java.lang.NullPointerException
- if the given string isnull
ArgumentSyntaxException
- if the given string does not have the correct syntax.
-
valueOfLiberal
public static AbstractISODateTime valueOfLiberal(java.lang.String string) throws ArgumentSyntaxException
Returns an ISO date or date time object holding the value of the specified string.Liberal parsing makes the following allowances:
- Seconds are considered optional.
- Whitespace before and after the date/time is allowed.
- The looser RFC 3339 Internet timestamp format is allowed, allowing the UTC designator, 90, for example.
- If time is present, an
ISODateTime
is returned; otherwise, anISODate
is returned. - Delimiters are optional.
- Parameters:
string
- The string to be parsed as a date time.- Returns:
- An ISO date time object represented by the string.
- Throws:
java.lang.NullPointerException
- if the given string isnull
ArgumentSyntaxException
- if the given string does not have the correct syntax.
-
toCalendar
public java.util.GregorianCalendar toCalendar()
Returns a calendar representing this date and time for the default locale. If this object has no time information, midnight UTC will be assumed.- Returns:
- A calendar representing this date time in the default locale.
- See Also:
Locale.getDefault()
-
toCalendar
public java.util.GregorianCalendar toCalendar(java.util.Locale locale)
Returns a calendar representing this date and time. If this object has no time information, midnight UTC will be assumed.- Parameters:
locale
- The locale for which a calendar should be returned.- Returns:
- A calendar representing this date time in the given locale.
- Throws:
java.lang.NullPointerException
- if the given locale isnull
.
-
toDate
public abstract java.util.Date toDate(java.util.TimeZone timeZone)
Returns a date that represents this temporal information in the given time zone.- Parameters:
timeZone
- The time zone which the date should represent.- Returns:
- The date this object represents in relation to the given time zone.
- Throws:
java.lang.NullPointerException
- if the given time zone isnull
.
-
toISODate
public abstract ISODate toISODate()
Returns the date portion of this date and time.- Returns:
- A date and time object with only the date part of this instance.
-
toString
public java.lang.String toString()
Returns the canonical lexical representation of this date time in the form "YYYY-MM-DDThh:mm:ss[.s+]+/-hh:mm".- Specified by:
toString
in interfaceISOTemporal
- Overrides:
toString
in classTime
- Returns:
- The canonical lexical representation of this date time.
-
-