ezvcard.util
Class PartialDate

java.lang.Object
  extended by ezvcard.util.PartialDate

public final class PartialDate
extends Object

Represents a date in which some of the components are missing. This is used to represent reduced accuracy and truncated dates, as defined in ISO8601.

A truncated date is a date where the "lesser" components are missing. For example, "12:30" is truncated because the "seconds" component is missing.

 PartialDate date = PartialDate.time(12, 30, null);
 

A reduced accuracy date is a date where the "greater" components are missing. For example, "April 20" is reduced accuracy because the "year" component is missing.

 PartialDate date = PartialDate.date(null, 4, 20);
 

Author:
Michael Angstadt

Constructor Summary
PartialDate(Integer year, Integer month, Integer date, Integer hour, Integer minute, Integer second, UtcOffset offset)
           Creates a new partial date.
PartialDate(String string)
          Parses a partial date from a string.
 
Method Summary
static PartialDate date(Integer year, Integer month, Integer date)
           Creates a partial date containing only date components.
static PartialDate dateTime(Integer year, Integer month, Integer date, Integer hour, Integer minute, Integer second)
           Creates a partial date containing date and time components, without a timezone.
static PartialDate dateTime(Integer year, Integer month, Integer date, Integer hour, Integer minute, Integer second, UtcOffset offset)
           Creates a partial date containing date and time components.
 boolean equals(Object obj)
           
 Integer getDate()
          Gets the date component.
 Integer getHour()
          Gets the hour component.
 Integer getMinute()
          Gets the minute component.
 Integer getMonth()
          Gets the month component.
 Integer getSecond()
          Gets the second component.
 Integer[] getTimezone()
          Gets the timezone component.
 Integer getYear()
          Gets the year component.
 boolean hasDateComponent()
          Determines if there are any date components.
 int hashCode()
           
 boolean hasTimeComponent()
          Determines if there are any time components.
static PartialDate time(Integer hour, Integer minute, Integer second)
           Creates a partial date containing only time components.
static PartialDate time(Integer hour, Integer minute, Integer second, UtcOffset offset)
           Creates a partial date containing only time components.
 String toDateAndOrTime(boolean extended)
          Converts this partial date to its ISO 8601 representation.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PartialDate

public PartialDate(Integer year,
                   Integer month,
                   Integer date,
                   Integer hour,
                   Integer minute,
                   Integer second,
                   UtcOffset offset)

Creates a new partial date.

The following combinations are not allowed and will result in an IllegalArgumentException being thrown:

Parameters:
year - the year or null to exclude
month - the month or null to exclude
date - the day of the month or null to exclude
hour - the hour or null to exclude
minute - the minute or null to exclude
second - the second or null to exclude
offset - the UTC offset or null to exclude
Throws:
IllegalArgumentException - if an invalid combination is entered or a component value is invalid (e.g. a negative minute)

PartialDate

public PartialDate(String string)
Parses a partial date from a string.

Parameters:
string - the string (e.g. "--0420T15")
Method Detail

date

public static PartialDate date(Integer year,
                               Integer month,
                               Integer date)

Creates a partial date containing only date components.

The following combinations are not allowed and will result in an IllegalArgumentException being thrown:

Parameters:
year - the year or null to exclude
month - the month or null to exclude
date - the day of the month or null to exclude
Returns:
the partial date
Throws:
IllegalArgumentException - if an invalid combination is entered or a component value is invalid (e.g. a negative month)

time

public static PartialDate time(Integer hour,
                               Integer minute,
                               Integer second)

Creates a partial date containing only time components.

The following combinations are not allowed and will result in an IllegalArgumentException being thrown:

Parameters:
hour - the hour or null to exclude
minute - the minute or null to exclude
second - the second or null to exclude
Returns:
the partial date
Throws:
IllegalArgumentException - if an invalid combination is entered or a component value is invalid (e.g. a negative minute)

time

public static PartialDate time(Integer hour,
                               Integer minute,
                               Integer second,
                               UtcOffset offset)

Creates a partial date containing only time components.

The following combinations are not allowed and will result in an IllegalArgumentException being thrown:

Parameters:
hour - the hour or null to exclude
minute - the minute or null to exclude
second - the second or null to exclude
offset - the UTC offset or null to exclude
Returns:
the partial date
Throws:
IllegalArgumentException - if an invalid combination is entered or a component value is invalid (e.g. a negative minute)

dateTime

public static PartialDate dateTime(Integer year,
                                   Integer month,
                                   Integer date,
                                   Integer hour,
                                   Integer minute,
                                   Integer second)

Creates a partial date containing date and time components, without a timezone.

The following combinations are not allowed and will result in an IllegalArgumentException being thrown:

Parameters:
year - the year or null to exclude
month - the month or null to exclude
date - the day of the month or null to exclude
hour - the hour or null to exclude
minute - the minute or null to exclude
second - the second or null to exclude
Returns:
the partial date
Throws:
IllegalArgumentException - if an invalid combination is entered or a component value is invalid (e.g. a negative minute)

dateTime

public static PartialDate dateTime(Integer year,
                                   Integer month,
                                   Integer date,
                                   Integer hour,
                                   Integer minute,
                                   Integer second,
                                   UtcOffset offset)

Creates a partial date containing date and time components.

The following combinations are not allowed and will result in an IllegalArgumentException being thrown:

Parameters:
year - the year or null to exclude
month - the month or null to exclude
date - the day of the month or null to exclude
hour - the hour or null to exclude
minute - the minute or null to exclude
second - the second or null to exclude
offset - the UTC offset or null to exclude
Returns:
the partial date
Throws:
IllegalArgumentException - if an invalid combination is entered or a component value is invalid (e.g. a negative minute)

getYear

public Integer getYear()
Gets the year component.

Returns:
the year component or null if not set

getMonth

public Integer getMonth()
Gets the month component.

Returns:
the month component or null if not set

getDate

public Integer getDate()
Gets the date component.

Returns:
the date component or null if not set

getHour

public Integer getHour()
Gets the hour component.

Returns:
the hour component or null if not set

getMinute

public Integer getMinute()
Gets the minute component.

Returns:
the minute component or null if not set

getSecond

public Integer getSecond()
Gets the second component.

Returns:
the second component or null if not set

getTimezone

public Integer[] getTimezone()
Gets the timezone component.

Returns:
the timezone component (index 0 = hour, index 1 = minute) or null if not set

hasDateComponent

public boolean hasDateComponent()
Determines if there are any date components.

Returns:
true if it has at least one date component, false if not

hasTimeComponent

public boolean hasTimeComponent()
Determines if there are any time components.

Returns:
true if there is at least one time component, false if not

toDateAndOrTime

public String toDateAndOrTime(boolean extended)
Converts this partial date to its ISO 8601 representation.

Parameters:
extended - true to use extended format, false to use basic
Returns:
the ISO 8601 representation

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.