pkg dateTime Date - yshehab/SchoolRoomBooking GitHub Wiki
Date is an immutable class which contains methods needed for the School Booking project. Dates are intended to be used in Range instances.
Implements the Repeat interface.
public static int MONTH Field number for add method
public static int YEAR Field number for add method
public static int DAY Field number for add method
static Date dateNow()
Post-condition: returns a new Date instance representing the current date.
private Calendar calendar A Calendar.
None
public Date(int year, int month, int day)
Pre-condition: The date must be a valid date otherwise a RuntimeException will be thrown.
If year < 1000, 2000 will be added to it e.g. 121 will become 2121.
Month is 1 based, so January ## 1. So Calendar.MARCH etc. should not be used as it will create a date in February.
Post-condition: Initialises a new Date instance with the supplied parameters.
Date(Date date)
Post-condition: Returns a new instance of date with the same state as the supplied date argument
public equals(Object obj)
Post-condition: Returns true if obj is a Date object with the same calendar as the receiver, otherwise false.
public hashCode()
Post-condition: Returns the hashCode of the receiver. Consistent with equals().
public int compareTo(Date date)
Post-condition: Consistent with equals
Returns -1 if date is before the receiver
Returns 0 if date is the same as the receiver
Returns 1 if date is after the receiver
public String toString()
Post-condition: returns a String representation of the receiver
public Date add(RepeatRate toAdd)
Post-condition: returns a new Date instance with the specified amount of time (from the RepeatRate) added to the given field.
Date date1 # new Date(12, Calendar.March, 2012); //date is 12/4/2012
Or Date date2 # new Date(12, 2, 12); //date is 12/2/2012 month is 1 based
Date date3 # Date.dateNow(); //date3 is current date
Date date4 # date1.add(RepeatRate.MONTHLY); //date4 is 12/5/2012
You can create a Date for the 29th February for a year which isn_t a leap year. -- fixed