com.javaranch.common
Class JDate

java.lang.Object
  |
  +--com.javaranch.common.JDate
All Implemented Interfaces:
java.io.Serializable

public class JDate
extends java.lang.Object
implements java.io.Serializable

Date is tracked as an integer.

Technically, a Julian calendar is the calendar designed by Julius Caesar in 46 B.C. It has months and leap years much like the gregorian calendar we use now (designed by Pope Gregory the 13th in 1582). But for several years, computer geeks have counted the number of days since the beginning of a year or another point in time and referred to this as a "Julian Date". From here on out, any reference to a "julian date" means "the number of days since January 1, 0000". This class will behave as if the Gregorian calendar leap year system has been in place since January 1, 0000.

This class will behave as both a Julian date and a Gregorian date although the actual date will be stored as a single integer.

- - - - - - - - - - - - - - - - -

Copyright (c) 1998-2004 Paul Wheaton

You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton
See Also:
Serialized Form

Constructor Summary
JDate()
          Create a new JDate object with a default of zero.
JDate(GDate g)
          Create a new JDate object equal to a GDate object.
JDate(int julianDate)
          Create a new JDate object specified as the number of days since January 1, 0000.
JDate(int year, int month, int day)
          Create a new JDate object based on a year, month and day.
JDate(JDate julianDate)
          Create a new JDate object equal to another JDate object.
 
Method Summary
 void adjust(int adj)
          Adjust the date by the given value.
 void dec()
          Decrement the date by one.
 boolean equals(int julianDate)
          Compare this object to an integer.
 boolean equals(java.lang.Object obj)
           
 int get()
          Get the integer representation.
 java.util.Date getDate()
          Convert to a Date object.
 int getDay()
          Get the day of the month (not the day of the week).
 int getDOW()
          Get the day of the week (not the day of the month).
 java.lang.String getDOWString()
          Get the full day of the week name: "Monday", "Tuesday", "Wednesday", etc.
 GDate getGDate()
          Convert to a GDate object.
 java.lang.String getLongFormat()
          Get something like "Wednesday, September 22, 1999".
 int getMonth()
          Extract the month.
 java.lang.String getMonthString()
          Get the full month name: "January", "February", "March", etc.
 java.lang.String getShortFormat()
          Deprecated.  
 int getYear()
          Extract the year.
 int hashCode()
           
 void inc()
          Increment the date by one.
 void inc(int adjust)
          Increment the date by the given value.
static boolean isValid(GDate date)
          Report if the given date is valid or not.
 void set(GDate g)
          Set this object to be equal to a GDate object.
 void set(int newJulianDate)
          Set this object to be equal to an integer.
 void set(JDate newJulianDate)
          Set this object to be equal to another JDate object.
 void setDay(int newDay)
          Change just the day - the year and month values will be unmodified.
 void setMonth(int newMonth)
          Change just the month - the year and day values will be unmodified.
 void setYear(int newYear)
          Change just the year - the month and day values will be unmodified.
 java.lang.String toString()
          Returns the same thing as getLongFormat().
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JDate

public JDate()
Create a new JDate object with a default of zero.


JDate

public JDate(int julianDate)
Create a new JDate object specified as the number of days since January 1, 0000.


JDate

public JDate(JDate julianDate)
Create a new JDate object equal to another JDate object.


JDate

public JDate(int year,
             int month,
             int day)
Create a new JDate object based on a year, month and day.


JDate

public JDate(GDate g)
Create a new JDate object equal to a GDate object.

Method Detail

isValid

public static boolean isValid(GDate date)
Report if the given date is valid or not.


set

public void set(int newJulianDate)
Set this object to be equal to an integer.


set

public void set(JDate newJulianDate)
Set this object to be equal to another JDate object.


set

public void set(GDate g)
Set this object to be equal to a GDate object.


setYear

public void setYear(int newYear)
Change just the year - the month and day values will be unmodified.


setMonth

public void setMonth(int newMonth)
Change just the month - the year and day values will be unmodified.


setDay

public void setDay(int newDay)
Change just the day - the year and month values will be unmodified.


get

public int get()
Get the integer representation.


getYear

public int getYear()
Extract the year.


getMonth

public int getMonth()
Extract the month.


getMonthString

public java.lang.String getMonthString()
Get the full month name: "January", "February", "March", etc.


getDay

public int getDay()
Get the day of the month (not the day of the week).


getDOW

public int getDOW()
Get the day of the week (not the day of the month).

Zero is monday.


getDOWString

public java.lang.String getDOWString()
Get the full day of the week name: "Monday", "Tuesday", "Wednesday", etc.


getGDate

public GDate getGDate()
Convert to a GDate object.


getDate

public java.util.Date getDate()
Convert to a Date object.

Since a Date object has a time element, the time is set to noon.


getShortFormat

public java.lang.String getShortFormat()
Deprecated.  

Get something like "05-01-1999" for May 5th, 1999.


getLongFormat

public java.lang.String getLongFormat()
Get something like "Wednesday, September 22, 1999".


equals

public boolean equals(int julianDate)
Compare this object to an integer.


hashCode

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

equals

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

inc

public void inc()
Increment the date by one.


inc

public void inc(int adjust)
Increment the date by the given value.

Negative values will decrement.


dec

public void dec()
Decrement the date by one.


adjust

public void adjust(int adj)
Adjust the date by the given value.

Positive values will increment.

Negative values will decrement.


toString

public java.lang.String toString()
Returns the same thing as getLongFormat().

Overrides:
toString in class java.lang.Object


Copyright ©2004 Paul Wheaton All Rights Reserved