Package com.globalmentor.iso.datetime
Class ISODate
- java.lang.Object
-
- java.util.Date
-
- com.globalmentor.time.Time
-
- com.globalmentor.iso.datetime.AbstractISODateTime
-
- com.globalmentor.iso.datetime.ISODate
-
- All Implemented Interfaces:
ISOTemporal
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<java.util.Date>
public class ISODate extends AbstractISODateTime
The class representing an ISO date type. 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 ISODate(int year, int month, int day)
Date components constructor.ISODate(long time)
Millisecond time constructor in terms of UTC.ISODate(long time, java.util.TimeZone timeZone)
Millisecond time constructor in terms of the given time zone.protected
ISODate(ISOTemporalComponents temporalComponents)
Temporal component constructor.ISODate(java.util.Date date)
Date constructor in terms of UTC.ISODate(java.util.Date date, java.util.TimeZone timeZone)
Date constructor in terms the given time zone.ISODate(java.util.GregorianCalendar calendar)
Calendar constructor in terms of UTC.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.GregorianCalendar
toCalendar(java.util.TimeZone timeZone)
Returns a calendar that represents this temporal information in the given time zone.java.util.Date
toDate(java.util.TimeZone timeZone)
Returns a date that represents this temporal information in the given time zone.ISODate
toISODate()
Returns the date portion of this date and time.static ISODate
valueOf(java.lang.String string)
Returns an ISO date object holding the value of the specified string.static ISODate
valueOfLenient(java.lang.String string)
Returns an ISO date object holding the value of the specified string.static ISODate
valueOfLiberal(java.lang.String string)
Returns an ISO date object holding the value of the specified string.-
Methods inherited from class com.globalmentor.iso.datetime.AbstractISODateTime
append, getDay, getISOTime, getMonth, getYear, toCalendar, toCalendar, toString
-
-
-
-
Constructor Detail
-
ISODate
protected ISODate(ISOTemporalComponents temporalComponents)
Temporal component constructor.- Parameters:
temporalComponents
- The temporal components from which to construct the class.- Throws:
java.lang.NullPointerException
- if the given temporal components isnull
.
-
ISODate
public ISODate(int year, int month, int day)
Date components constructor. The underlyingDate
will be constructed in terms of UTC.- Parameters:
year
- The year, 0-9999.month
- The month, 1-12.day
- The day, 1-31.- Throws:
java.lang.IllegalArgumentException
- if one of the given arguments is outside the allowed range.
-
ISODate
public ISODate(java.util.GregorianCalendar calendar)
Calendar constructor in terms of UTC. Any time-related information of the given calendar will be lost; only the date will be kept, in terms of the calendar's time zone.- Parameters:
calendar
- The calendar representing the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC; and a time zone.- Throws:
java.lang.NullPointerException
- if the given calendar isnull
.
-
ISODate
public ISODate(java.util.Date date)
Date constructor in terms of UTC. Any time-related information of the given date will be lost; only the date will be kept, in terms of midnight UTC.- Parameters:
date
- The date representing the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.- Throws:
java.lang.NullPointerException
- if the given date isnull
.
-
ISODate
public ISODate(java.util.Date date, java.util.TimeZone timeZone)
Date constructor in terms the given time zone. Any time-related information of the given date will be lost; only the date will be kept, in terms of the given time zone.- Parameters:
date
- The date representing the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.timeZone
- The time zone in which the time should be interpreted.- Throws:
java.lang.NullPointerException
- if the given date and/or time zone isnull
.java.lang.IllegalArgumentException
- if a time zone was provided with an unsupported offset for the given time.
-
ISODate
public ISODate(long time)
Millisecond time constructor in terms of UTC. Any time-related information of the given time will be lost; only the date will be kept, in terms of midnight UTC.- Parameters:
time
- The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
-
ISODate
public ISODate(long time, java.util.TimeZone timeZone)
Millisecond time constructor in terms of the given time zone. Any time-related information of the given time will be lost; only the date will be kept, in terms of the given time zone.- Parameters:
time
- The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.timeZone
- The time zone in which the time should be interpreted.- Throws:
java.lang.NullPointerException
- if the given time zone isnull
.java.lang.IllegalArgumentException
- if a time zone was provided with an unsupported offset for the given time.
-
-
Method Detail
-
toDate
public java.util.Date toDate(java.util.TimeZone timeZone)
Returns a date that represents this temporal information in the given time zone.- Specified by:
toDate
in classAbstractISODateTime
- 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
.- See Also:
toCalendar(TimeZone)
-
toCalendar
public java.util.GregorianCalendar toCalendar(java.util.TimeZone timeZone)
Returns a calendar that represents this temporal information in the given time zone.- Parameters:
timeZone
- The time zone which the date should represent.- Returns:
- The calendar this object represents in relation to the given time zone.
- Throws:
java.lang.NullPointerException
- if the given time zone isnull
.
-
toISODate
public ISODate toISODate()
Returns the date portion of this date and time.- Specified by:
toISODate
in classAbstractISODateTime
- Returns:
- A date and time object with only the date part of this instance.
-
valueOf
public static ISODate valueOf(java.lang.String string) throws ArgumentSyntaxException
Returns an ISO date object holding the value of the specified string.- Parameters:
string
- The string to be parsed as a date.- Returns:
- An ISO date 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.
-
valueOfLenient
public static ISODate valueOfLenient(java.lang.String string) throws ArgumentSyntaxException
Returns an ISO date 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.
- Parameters:
string
- The string to be parsed as a date.- Returns:
- An ISO date 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 ISODate valueOfLiberal(java.lang.String string) throws ArgumentSyntaxException
Returns an ISO date 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.
- Delimiters are optional.
- Parameters:
string
- The string to be parsed as a date.- Returns:
- An ISO date 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.
-
-