com.raj.extensions
Class ExtendedGCalendar

java.lang.Object
  |
  +--java.util.Calendar
        |
        +--java.util.GregorianCalendar
              |
              +--com.raj.extensions.ExtendedGCalendar
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class ExtendedGCalendar
extends java.util.GregorianCalendar

Justs adds a few utility methods to the Calendar class that should have been there in the first place.

Author:
Rajnish Bhaskar
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.GregorianCalendar
AD, BC
 
Fields inherited from class java.util.Calendar
AM, AM_PM, APRIL, areFieldsSet, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DST_OFFSET, ERA, FEBRUARY, FIELD_COUNT, fields, FRIDAY, HOUR, HOUR_OF_DAY, isSet, isTimeSet, JANUARY, JULY, JUNE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, time, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, YEAR, ZONE_OFFSET
 
Constructor Summary
ExtendedGCalendar()
          default constructor, sets up a new calendar for today
ExtendedGCalendar(int year, int month, int date)
          contstructor that sets the date of this object
 
Method Summary
 int daysBetween(java.util.Calendar theDate)
          calculates how many days that there are between this and the given parameter, inclusive, where the order of the dates doesn't matter.
 int daysBetween(java.util.Calendar theDate, boolean precedesMatters)
          calculates how many days that there are between this and the given parameter, inclusive.
 int daysInMonth()
          returns the number of days in the date represented by this object
 int daysInMonth(int month)
          returns the number of days in the given month combination, assuming that this is not a leapyear
 int daysInMonth(int month, int year)
          returns the number of days in the given month/year combination
 java.lang.String getDateString()
          Returns the date of this ExtendedGCalendar object in international standard date format -- YYYY-MMM-DD
 java.lang.String nameOfMonth(int month)
          takes an integer from 0 to 11 and returns the month associated with that number, 0= January, 1= February etc
 
Methods inherited from class java.util.GregorianCalendar
add, computeFields, computeTime, equals, getActualMaximum, getActualMinimum, getGreatestMinimum, getGregorianChange, getLeastMaximum, getMaximum, getMinimum, hashCode, isLeapYear, roll, roll, setGregorianChange
 
Methods inherited from class java.util.Calendar
after, before, clear, clear, clone, complete, get, getAvailableLocales, getFirstDayOfWeek, getInstance, getInstance, getInstance, getInstance, getMinimalDaysInFirstWeek, getTime, getTimeInMillis, getTimeZone, internalGet, isLenient, isSet, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, setTimeZone, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExtendedGCalendar

public ExtendedGCalendar()
default constructor, sets up a new calendar for today


ExtendedGCalendar

public ExtendedGCalendar(int year,
                         int month,
                         int date)
contstructor that sets the date of this object

Parameters:
year - the year of the date that we want
month - the month of the date that we want (0 -- 11)
date - the date of the month of the date that we want
Method Detail

nameOfMonth

public java.lang.String nameOfMonth(int month)
takes an integer from 0 to 11 and returns the month associated with that number, 0= January, 1= February etc

Parameters:
month - the month number that you want a name for
Returns:
the name of the month

daysInMonth

public int daysInMonth()
returns the number of days in the date represented by this object

Returns:
the number of days this month

daysInMonth

public int daysInMonth(int month,
                       int year)
returns the number of days in the given month/year combination

Parameters:
month - the month that you want to find the num of days for
year - needed for leapyear calculations
Returns:
the number of days in the given month/year combination, or -1 if the month is invalid (0 <= x <= 11)

daysInMonth

public int daysInMonth(int month)
returns the number of days in the given month combination, assuming that this is not a leapyear

Parameters:
month - the month that you want to find the num of days for
Returns:
the number of days in the given month
See Also:
daysInMonth(int month, int year)

daysBetween

public int daysBetween(java.util.Calendar theDate,
                       boolean precedesMatters)
calculates how many days that there are between this and the given parameter, inclusive.

Note: I don't think that this is fully debugged yet! Use at your own risk!!

Parameters:
precedesMatters - if this is true, then it will check to make sure that this precedes the parameter, and if it does not, then it returns -1
Returns:
the number of days between the this and the given parameter. If this does not precede the given parameter when precedesMatters is true, then -1 is returned.

daysBetween

public int daysBetween(java.util.Calendar theDate)
calculates how many days that there are between this and the given parameter, inclusive, where the order of the dates doesn't matter.

Returns:
the number of days between the ImprovedCalendar object that this method is attached to and the given parameter.

getDateString

public java.lang.String getDateString()
Returns the date of this ExtendedGCalendar object in international standard date format -- YYYY-MMM-DD