corejava
Class Day

java.lang.Object
  |
  +--corejava.Day

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

Stores dates and perform date arithmetic. This is another date class, but more convenient that java.util.Date or java.util.Calendar

See Also:
Serialized Form

Field Summary
static int FRIDAY
           
static int MONDAY
           
static int SATURDAY
           
static int SUNDAY
           
static int THURSDAY
           
static int TUESDAY
           
static int WEDNESDAY
           
 
Constructor Summary
Day()
          Constructs today's date
Day(int yyyy, int m, int d)
          Constructs a specific date
 
Method Summary
 void advance(int n)
          Advances this day by n days.
 java.lang.Object clone()
          Makes a bitwise copy of a Day object
 int daysBetween(Day b)
          The number of days between this and day parameter
 boolean equals(java.lang.Object obj)
          Compares this Day against another object
 int getDay()
          Gets the day of the month
 int getMonth()
          Gets the month
 int getYear()
          Gets the year
 java.lang.String toString()
          A string representation of the day
 int weekday()
          Gets the weekday
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SUNDAY

public static int SUNDAY

MONDAY

public static int MONDAY

TUESDAY

public static int TUESDAY

WEDNESDAY

public static int WEDNESDAY

THURSDAY

public static int THURSDAY

FRIDAY

public static int FRIDAY

SATURDAY

public static int SATURDAY
Constructor Detail

Day

public Day()
Constructs today's date

Day

public Day(int yyyy,
           int m,
           int d)
Constructs a specific date
Parameters:
yyyy - year (full year, e.g., 1996, not starting from 1900)
m - month
d - day
Throws:
java.lang.IllegalArgumentException - if yyyy m d not a valid date
Method Detail

advance

public void advance(int n)
Advances this day by n days. For example. d.advance(30) adds thirdy days to d
Parameters:
n - the number of days by which to change this day (can be < 0)

getDay

public int getDay()
Gets the day of the month
Returns:
the day of the month (1...31)

getMonth

public int getMonth()
Gets the month
Returns:
the month (1...12)

getYear

public int getYear()
Gets the year
Returns:
the year (counting from 0, not from 1900)

weekday

public int weekday()
Gets the weekday
Returns:
the weekday (SUNDAY, ..., SATURDAY)

daysBetween

public int daysBetween(Day b)
The number of days between this and day parameter
Parameters:
b - any date
Returns:
the number of days between this and day parameter and b (> 0 if this day comes after b)

toString

public java.lang.String toString()
A string representation of the day
Returns:
a string representation of the day
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Makes a bitwise copy of a Day object
Returns:
a bitwise copy of a Day object
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Compares this Day against another object
Parameters:
obj - another object
Returns:
true if the other object is identical to this Day object
Overrides:
equals in class java.lang.Object