jimmc.util
Class DateSpec

java.lang.Object
  |
  +--jimmc.util.DateSpec
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class DateSpec
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

A representation of date or date/time information with specified precision. This can encode year/month/day/hour/minute/second/fractionalSecond, or any less precise subset. There are two primary differences between this and Date or Timestamp:

  1. DateSpec allows representing partial date information, thus can distinguish between "2002", "Jan, 2002" and "Jan 1, 2002".
  2. DateSpec does not encode the time zone. All times are local times.

See Also:
Serialized Form

Field Summary
protected  java.util.Date date
          Our date.
protected  java.text.SimpleDateFormat dateFormat
          The format for this instance.
protected  int precision
          The precision of our date.
static int PRECISION_DAY
          Precision to the day.
static int PRECISION_FRACTION
          Precision to the fractional second.
static int PRECISION_HOUR
          Precision to the hour.
static int PRECISION_MINUTE
          Precision to the minute.
static int PRECISION_MONTH
          Precision to the month.
static int PRECISION_NONE
          No data specified.
static int PRECISION_SECOND
          Precision to the second.
static int PRECISION_YEAR
          Precision to the year.
 
Constructor Summary
DateSpec()
          Create a DateSpec with no data.
DateSpec(java.util.Date date)
          Create a DateSpec from a Date.
DateSpec(java.util.Date date, int precision)
          Create a DateSpec from a Date and precision.
DateSpec(java.lang.String s)
          Create a DateSpec from a string.
 
Method Summary
 java.lang.Object clone()
           
 int compareTo(java.lang.Object o)
           
 java.util.Date getDate()
          Get our date.
protected static java.text.SimpleDateFormat getDateFormat(int precision)
          Get our canonical date format according to the precision.
 int getPrecision()
          Get our precision.
protected  void setDateFormat()
          Set our canonical date format according to the precision.
 void setPrecision(int precision)
          Set our precision.
 java.lang.String toString()
          Convert to a String.
static DateSpec valueOf(java.lang.String s)
          Create a DateSpec from a string.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

date

protected java.util.Date date
Our date.

precision

protected int precision
The precision of our date.

PRECISION_NONE

public static final int PRECISION_NONE
No data specified.

PRECISION_YEAR

public static final int PRECISION_YEAR
Precision to the year.

PRECISION_MONTH

public static final int PRECISION_MONTH
Precision to the month.

PRECISION_DAY

public static final int PRECISION_DAY
Precision to the day.

PRECISION_HOUR

public static final int PRECISION_HOUR
Precision to the hour.

PRECISION_MINUTE

public static final int PRECISION_MINUTE
Precision to the minute.

PRECISION_SECOND

public static final int PRECISION_SECOND
Precision to the second.

PRECISION_FRACTION

public static final int PRECISION_FRACTION
Precision to the fractional second.

dateFormat

protected java.text.SimpleDateFormat dateFormat
The format for this instance.
Constructor Detail

DateSpec

public DateSpec()
Create a DateSpec with no data.

DateSpec

public DateSpec(java.util.Date date,
                int precision)
Create a DateSpec from a Date and precision.

DateSpec

public DateSpec(java.lang.String s)
Create a DateSpec from a string.

DateSpec

public DateSpec(java.util.Date date)
Create a DateSpec from a Date. The precision is set to PRECISION_SECOND.
Method Detail

getDate

public java.util.Date getDate()
Get our date.

setPrecision

public void setPrecision(int precision)
Set our precision.

getPrecision

public int getPrecision()
Get our precision.

getDateFormat

protected static java.text.SimpleDateFormat getDateFormat(int precision)
Get our canonical date format according to the precision.

setDateFormat

protected void setDateFormat()
Set our canonical date format according to the precision.

toString

public java.lang.String toString()
Convert to a String. The format used is the same as the standard SQL format, YYYY-MM-DD HH:MM:SS.F, or a truncated version of that format when less precision has been specified.
Overrides:
toString in class java.lang.Object

valueOf

public static DateSpec valueOf(java.lang.String s)
Create a DateSpec from a string. Parses the same format of string as is created by toString().

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable