org.nakedobjects.applib.value
Class Date

java.lang.Object
  extended by org.nakedobjects.applib.value.Magnitude
      extended by org.nakedobjects.applib.value.Date
All Implemented Interfaces:
java.io.Serializable

public class Date
extends Magnitude

Value object representing a date (not time) value.

TODO: other methods to implement comparison methods:

See Also:
Serialized Form

Constructor Summary
Date()
          Create a Date object for today's date.
Date(java.util.Date date)
          Create a Date object based on the specified Java date object.
Date(int year, int month, int day)
          Create a Date object set to the specified day, month and year.
 
Method Summary
 Date add(int years, int months, int days)
          Add the specified days, years and months to this date value and return a new date object containing the result.
protected  Date createDate(java.util.Date time)
           
 java.util.Date dateValue()
          Return this date value as a Java Date object.
 Date endOfMonth()
          Calculates, and returns, a date representing the last day of the month relative to the current date.
 boolean equals(java.lang.Object obj)
           
 int getDay()
          Return the day from this date, in the range 1 - 31.
 int getDayOfWeek()
          Calculates, and returns, an int representing the day of the week relative to the current date.
 int getMonth()
          Return the month from this date, in the range 1 - 12.
 int getYear()
          Return the year from this date.
 boolean isEqualTo(Magnitude date)
          Returns true if the date of this object has the same value as the specified date
 boolean isLessThan(Magnitude date)
          Returns true if the time of this object is earlier than the specified time
 boolean sameDayOfMonthAs(Date as)
          Determines if this date and the specified date represent the same day of the month, eg both dates are for the 3rd.
 boolean sameDayOfWeekAs(Date as)
          Determines if this date and the specified date represent the same day of the week, eg both dates are on a Tuesday.
 boolean sameDayOfYearAs(Date as)
          Determines if this date and the specified date represent the same day of the year, eg both dates are for the 108th day of the year.
 boolean sameMonthAs(Date as)
          Determines if this date and the specified date represent the same month, eg both dates are for the March.
 boolean sameWeekAs(Date as)
          Determines if this date and the specified date represent the same week in the year, eg both dates are the for the 18th week of the year.
 boolean sameYearAs(Date as)
          Determines if this date and the specified date represent the same year.
 Date startOfMonth()
          Calculates, and returns, a date representing the first day of the month relative to the current date.
 Date startOfWeek()
          Calculates, and returns, a date representing the first day of the week relative to the current date.
 Date startOfYear()
          Calculates, and returns, a date representing the first day of the year relative to the current date.
 java.lang.String title()
           
 java.lang.String toString()
           
 
Methods inherited from class org.nakedobjects.applib.value.Magnitude
isBetween, isGreaterThan, isGreaterThanOrEqualTo, isLessThanOrEqualTo, max, min
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Date

public Date()
Create a Date object for today's date.


Date

public Date(int year,
            int month,
            int day)
Create a Date object set to the specified day, month and year.


Date

public Date(java.util.Date date)
Create a Date object based on the specified Java date object. The time portion of the Java date is disposed of.

Method Detail

createDate

protected Date createDate(java.util.Date time)

add

public Date add(int years,
                int months,
                int days)
Add the specified days, years and months to this date value and return a new date object containing the result.


dateValue

public java.util.Date dateValue()
Return this date value as a Java Date object.

See Also:
Date

endOfMonth

public Date endOfMonth()
Calculates, and returns, a date representing the last day of the month relative to the current date.


equals

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

getDay

public int getDay()
Return the day from this date, in the range 1 - 31.


getDayOfWeek

public int getDayOfWeek()
Calculates, and returns, an int representing the day of the week relative to the current date. With Mon = 0 through to Sun = 6


getMonth

public int getMonth()
Return the month from this date, in the range 1 - 12.


getYear

public int getYear()
Return the year from this date.


isEqualTo

public boolean isEqualTo(Magnitude date)
Returns true if the date of this object has the same value as the specified date

Specified by:
isEqualTo in class Magnitude

isLessThan

public boolean isLessThan(Magnitude date)
Returns true if the time of this object is earlier than the specified time

Specified by:
isLessThan in class Magnitude

sameDayOfMonthAs

public boolean sameDayOfMonthAs(Date as)
Determines if this date and the specified date represent the same day of the month, eg both dates are for the 3rd.


sameDayOfWeekAs

public boolean sameDayOfWeekAs(Date as)
Determines if this date and the specified date represent the same day of the week, eg both dates are on a Tuesday.


sameDayOfYearAs

public boolean sameDayOfYearAs(Date as)
Determines if this date and the specified date represent the same day of the year, eg both dates are for the 108th day of the year.


sameMonthAs

public boolean sameMonthAs(Date as)
Determines if this date and the specified date represent the same month, eg both dates are for the March.


sameWeekAs

public boolean sameWeekAs(Date as)
Determines if this date and the specified date represent the same week in the year, eg both dates are the for the 18th week of the year.


sameYearAs

public boolean sameYearAs(Date as)
Determines if this date and the specified date represent the same year.


startOfMonth

public Date startOfMonth()
Calculates, and returns, a date representing the first day of the month relative to the current date.


startOfWeek

public Date startOfWeek()
Calculates, and returns, a date representing the first day of the week relative to the current date.


startOfYear

public Date startOfYear()
Calculates, and returns, a date representing the first day of the year relative to the current date.


title

public java.lang.String title()

toString

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


Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.