com.moneydance.apps.md.model.time
Class MDDate

java.lang.Object
  extended by com.moneydance.apps.md.model.time.MDDate
All Implemented Interfaces:
Stringifyable

public final class MDDate
extends java.lang.Object
implements Stringifyable

The MDDate class is the Moneydance representation of a date. In essence, this is simply a day, month, year instance. There is no time or time zone. This class also contains utility methods for comparing and computing with dates.

This class is immutable.

Author:
Jay Detwiler

Constructor Summary
MDDate()
          Create an MDDate for today.
MDDate(java.util.Date date)
          Create an MDDate from the given Date.
MDDate(int value)
          Create an MDDate from the given int representation.
MDDate(int day, int month, int year)
          Create an MDDate with the given day, month and year.
 
Method Summary
 boolean equals(java.lang.Object o)
           
static MDDate fromString(java.lang.String string)
           
 int hashCode()
           
 boolean isAfter(MDDate date)
           
 boolean isBefore(MDDate date)
           
static boolean isValidDate(int value)
          Returns true if the given int is a valid date representation.
 java.util.Date toDate()
          Returns this date as a Date with the time set to noon.
 int toInt()
          Returns this date as an int where the integer value is an eight digit number with the digits put together as YYYYMMDD.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MDDate

public MDDate()
Create an MDDate for today.


MDDate

public MDDate(java.util.Date date)
Create an MDDate from the given Date.

Parameters:
date - a Date

MDDate

public MDDate(int value)
       throws java.lang.IllegalArgumentException
Create an MDDate from the given int representation.

Parameters:
value - an int representation of a date
Throws:
java.lang.IllegalArgumentException - if the given int is not a valid date
See Also:
toInt()

MDDate

public MDDate(int day,
              int month,
              int year)
Create an MDDate with the given day, month and year. Unlike MDDate(int), this constructor is lenient and will compute a valid date from the integer valus given. For example, the argument list 32,1,2000 would give an MDDate with the value of Ferbuary 1st, 2000.

Parameters:
day - a day value with 1 meaning the first of the month
month - a month value with 1 meaning January
year - a year value taken as the exact value (ie not a two digit year 09 meaning 2009)
Method Detail

isValidDate

public static boolean isValidDate(int value)
Returns true if the given int is a valid date representation. The integer value must have a valid day (1-31, depending on the month) in the tens/ones positions, a valid month (1-12) in the thousands/hundreds positions and a valid year (greater than 1900) in the ten millions through ten thousands positions.

Parameters:
value - an int representation of a date
Returns:
true if the given int is a valid date representation.

toInt

public int toInt()
Returns this date as an int where the integer value is an eight digit number with the digits put together as YYYYMMDD.

Returns:
this date as an int

toDate

public java.util.Date toDate()
Returns this date as a Date with the time set to noon.

Returns:
this date as a Date.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromString

public static MDDate fromString(java.lang.String string)
                         throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

isBefore

public boolean isBefore(MDDate date)

isAfter

public boolean isAfter(MDDate date)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object