com.plumtree.openfoundation.util
Class XPCalendar

java.lang.Object
  extended by com.plumtree.openfoundation.util.XPCalendar

public class XPCalendar
extends java.lang.Object

XPCalendar is a wrapper over GregorianCalendar, which is the standard calendar used by most of the world.


Field Summary
static int AM
          Value of the AM_PM field indicating the period of the day from midnight to just before noon.
static int AM_PM
          Field number for Get and Set indicating whether the HOUR is before or after noon.
static int DATE
          Field number for Get and Set indicating the day of the month.
static int DAY_OF_MONTH
          Field number for Get and Set indicating the day of the month.
static int DAY_OF_WEEK
          Field number for Get and Set indicating the day of the week.
static int DAY_OF_WEEK_IN_MONTH
          Field number for Get and Set indicating the ordinal number of the day of the week within the current month.
static int DAY_OF_YEAR
          Field number for Get and Set indicating the day number within the current year.
static int ERA
          Field number for Get and Set indicating the era, e.g., AD or BC in the Julian calendar.
static java.lang.String EXPECTED_VALID_DAY_EXCEPTION_MSG
          Valid values for DAY are 1 and above.
static java.lang.String EXPECTED_VALID_MONTH_EXCEPTION_MSG
          Valid values for MONTH are 1-12.
static java.lang.String EXPECTED_VALID_YEAR_EXCEPTION_MSG
          Year must be a positive number.
static int FRIDAY
          Value of the DAY_OF_WEEK field indicating Friday.
protected  java.util.GregorianCalendar gc
          Internal GregorianCalendar.
static int HOUR
          Field number for Get and Set indicating the hour of the morning or afternoon.
static int HOUR_OF_DAY
          Field number for Get and Set indicating the hour of the day.
static int MILLISECOND
          Field number for Get and Set indicating the millisecond within the second.
static int MINUTE
          Field number for Get and Set indicating the minute within the hour.
static int MONDAY
          Value of the DAY_OF_WEEK field indicating Monday.
static int MONTH
          Field number for Get and Set indicating the month.
static int PM
          Value of the AM_PM field indicating the period of the day from noon to just before midnight.
static int SATURDAY
          Value of the DAY_OF_WEEK field indicating Saturday.
static int SECOND
          Field number for Get and Set indicating the second within the minute.
static int SUNDAY
          Value of the DAY_OF_WEEK field indicating Sunday.
static int THURSDAY
          Value of the DAY_OF_WEEK field indicating Thursday.
static int TUESDAY
          Value of the DAY_OF_WEEK field indicating Tuesday.
static int WEDNESDAY
          Value of the DAY_OF_WEEK field indicating Wednesday.
static int WEEK_OF_MONTH
          Field number for Get and Set indicating the week number within the current month.
static int WEEK_OF_YEAR
          Field number for Get and Set indicating the week number within the current year.
static int YEAR
          Field number for Get and Set indicating the year.
 
Method Summary
 void Add(int unit, int amount)
          Updates the calendar by adding the given amount of units to its current value.
 boolean After(XPCalendar when)
          Compares the time field records.
 boolean Before(XPCalendar when)
          Compares the time field records.
 void Clear()
          Clears the values of all the time fields.
 int Get(int unit)
          Gets the value for a given time field.
 int GetActualMaximum(int unit)
          Return the maximum value that this field could have, given the current date.
 int GetActualMinimum(int unit)
          Return the minimum value that this field could have, given the current date.
 int GetFirstDayOfWeek()
          Gets the first day of the week; e.g., Sunday in US, Monday in France.
 XPDateTime GetGregorianChange()
          Gets the Gregorian Calendar change date.
static XPCalendar GetInstance()
          Gets a calendar using the default time zone and locale.
static XPCalendar GetInstance(int year, int month, int day)
          Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.
static XPCalendar GetInstance(int year, int month, int day, int hour, int minute)
          Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
static XPCalendar GetInstance(int year, int month, int day, int hour, int minute, int second)
          Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.
static XPCalendar GetInstance(XPLocale locale)
          Gets a calendar using the default time zone and specified locale.
static XPCalendar GetInstance(XPTimeZone timezone)
          Gets a calendar using the specified time zone and default locale.
static XPCalendar GetInstance(XPTimeZone timezone, XPLocale locale)
          Gets a calendar with the specified time zone and locale.
 int GetMaximum(int unit)
          Gets the maximum value for the given time field.
 int GetMinimum(int unit)
          Gets the minimum value for the given time field.
 XPDateTime GetTime()
          Gets this Calendar's current time.
 XPTimeZone GetTimeZone()
          Gets the time zone.
 java.util.GregorianCalendar GetUnderlyingObject()
          Returns the platform specific object that this class wraps.
 void Set(int unit, int value)
          Sets the time field with the given value.
 void Set(int year, int month, int day)
          Sets the values for the fields year, month, and day.
 void Set(int year, int month, int day, int hour, int minute)
          Sets the values for the fields year, month, day, hour, and minute.
 void Set(int year, int month, int day, int hour, int minute, int second)
          Sets the values for the fields year, month, day, hour, minute, and second.
 void SetTime(XPDateTime date)
          Sets this Calendar's current time with the given XPDateTime.
 void SetTimeZone(XPTimeZone timezone)
          Sets the timezone for the calendar.
 java.lang.String toString()
          Returns string representation of this XPCalendar forwarding from ToString().
 java.lang.String ToString()
          Returns string representation of this XPCalendar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERA

public static final int ERA
Field number for Get and Set indicating the era, e.g., AD or BC in the Julian calendar.

See Also:
Constant Field Values

YEAR

public static final int YEAR
Field number for Get and Set indicating the year.

See Also:
Constant Field Values

MONTH

public static final int MONTH
Field number for Get and Set indicating the month.

See Also:
Constant Field Values

WEEK_OF_YEAR

public static final int WEEK_OF_YEAR
Field number for Get and Set indicating the week number within the current year. The first week of the year has value 1.

See Also:
Constant Field Values

WEEK_OF_MONTH

public static final int WEEK_OF_MONTH
Field number for Get and Set indicating the week number within the current month. The first week of the month has value 1.

See Also:
Constant Field Values

DATE

public static final int DATE
Field number for Get and Set indicating the day of the month. This is a synonym for DAY_OF_MONTH. The first day of the month has value 1.

See Also:
Constant Field Values

DAY_OF_MONTH

public static final int DAY_OF_MONTH
Field number for Get and Set indicating the day of the month. This is a synonym for DATE. The first day of the month has value 1.

See Also:
Constant Field Values

DAY_OF_YEAR

public static final int DAY_OF_YEAR
Field number for Get and Set indicating the day number within the current year. The first day of the year has value 1.

See Also:
Constant Field Values

DAY_OF_WEEK

public static final int DAY_OF_WEEK
Field number for Get and Set indicating the day of the week. This field takes values SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY.

See Also:
Constant Field Values

DAY_OF_WEEK_IN_MONTH

public static final int DAY_OF_WEEK_IN_MONTH
Field number for Get and Set indicating the ordinal number of the day of the week within the current month.

See Also:
Constant Field Values

AM_PM

public static final int AM_PM
Field number for Get and Set indicating whether the HOUR is before or after noon. E.g., at 10:04:15.250 PM the AM_PM is PM.

See Also:
Constant Field Values

HOUR

public static final int HOUR
Field number for Get and Set indicating the hour of the morning or afternoon. HOUR is used for the 12-hour clock. E.g., at 10:04:15.250 PM the HOUR is 10.

See Also:
Constant Field Values

HOUR_OF_DAY

public static final int HOUR_OF_DAY
Field number for Get and Set indicating the hour of the day. HOUR_OF_DAY is used for the 24-hour clock. E.g., at 10:04:15.250 PM the HOUR_OF_DAY is 22.

See Also:
Constant Field Values

MINUTE

public static final int MINUTE
Field number for Get and Set indicating the minute within the hour. E.g., at 10:04:15.250 PM the MINUTE is 4.

See Also:
Constant Field Values

SECOND

public static final int SECOND
Field number for Get and Set indicating the second within the minute. E.g., at 10:04:15.250 PM the SECOND is 15.

See Also:
Constant Field Values

MILLISECOND

public static final int MILLISECOND
Field number for Get and Set indicating the millisecond within the second. E.g., at 10:04:15.250 PM the MILLISECOND is 250.

See Also:
Constant Field Values

AM

public static final int AM
Value of the AM_PM field indicating the period of the day from midnight to just before noon.

See Also:
Constant Field Values

PM

public static final int PM
Value of the AM_PM field indicating the period of the day from noon to just before midnight.

See Also:
Constant Field Values

SUNDAY

public static final int SUNDAY
Value of the DAY_OF_WEEK field indicating Sunday.

See Also:
Constant Field Values

MONDAY

public static final int MONDAY
Value of the DAY_OF_WEEK field indicating Monday.

See Also:
Constant Field Values

TUESDAY

public static final int TUESDAY
Value of the DAY_OF_WEEK field indicating Tuesday.

See Also:
Constant Field Values

WEDNESDAY

public static final int WEDNESDAY
Value of the DAY_OF_WEEK field indicating Wednesday.

See Also:
Constant Field Values

THURSDAY

public static final int THURSDAY
Value of the DAY_OF_WEEK field indicating Thursday.

See Also:
Constant Field Values

FRIDAY

public static final int FRIDAY
Value of the DAY_OF_WEEK field indicating Friday.

See Also:
Constant Field Values

SATURDAY

public static final int SATURDAY
Value of the DAY_OF_WEEK field indicating Saturday.

See Also:
Constant Field Values

gc

protected java.util.GregorianCalendar gc
Internal GregorianCalendar.


EXPECTED_VALID_MONTH_EXCEPTION_MSG

public static final java.lang.String EXPECTED_VALID_MONTH_EXCEPTION_MSG
Valid values for MONTH are 1-12.

See Also:
Constant Field Values

EXPECTED_VALID_DAY_EXCEPTION_MSG

public static final java.lang.String EXPECTED_VALID_DAY_EXCEPTION_MSG
Valid values for DAY are 1 and above.

See Also:
Constant Field Values

EXPECTED_VALID_YEAR_EXCEPTION_MSG

public static final java.lang.String EXPECTED_VALID_YEAR_EXCEPTION_MSG
Year must be a positive number.

See Also:
Constant Field Values
Method Detail

GetInstance

public static XPCalendar GetInstance()
Gets a calendar using the default time zone and locale.

Returns:
An instance of XPCalendar

GetInstance

public static XPCalendar GetInstance(int year,
                                     int month,
                                     int day)
Constructs a GregorianCalendar with the given date set in the default time zone with the default locale.

Parameters:
year - yyyy
month - (1-12)
day - (1-31)
Returns:
XPCalendar object

GetInstance

public static XPCalendar GetInstance(int year,
                                     int month,
                                     int day,
                                     int hour,
                                     int minute)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.

Parameters:
year - yyyy
month - (1-12)
day - (1-31)
hour - (0-23)
minute - (0-59)
Returns:
XPCalendar Object

GetInstance

public static XPCalendar GetInstance(int year,
                                     int month,
                                     int day,
                                     int hour,
                                     int minute,
                                     int second)
Constructs a GregorianCalendar with the given date and time set for the default time zone with the default locale.

Parameters:
year - yyyy
month - (1-12)
day - (1-31)
hour - (0-23)
minute - (0-59)
second - (0-59)
Returns:
XPCalendar Object

GetInstance

public static XPCalendar GetInstance(XPLocale locale)
Gets a calendar using the default time zone and specified locale.

Parameters:
locale - locale value
Returns:
An instance of XPCalendar

GetInstance

public static XPCalendar GetInstance(XPTimeZone timezone)
Gets a calendar using the specified time zone and default locale.

Parameters:
timezone - value
Returns:
An instance of XPCalendar

GetInstance

public static XPCalendar GetInstance(XPTimeZone timezone,
                                     XPLocale locale)
Gets a calendar with the specified time zone and locale.

Parameters:
timezone - Zone Reference
locale - Locale value
Returns:
An instance of XPCalendar

Add

public void Add(int unit,
                int amount)
Updates the calendar by adding the given amount of units to its current value.

Parameters:
unit - contains the unit of amount
amount - actual value to be added

After

public boolean After(XPCalendar when)
Compares the time field records.

Parameters:
when - is after the time of XPCalendar
Returns:
true if the current time of this XPCalendar is after the time of XPCalendar when; false otherwise

Before

public boolean Before(XPCalendar when)
Compares the time field records.

Parameters:
when - is after the time of XPCalendar
Returns:
true if the current time of this XPCalendar is before the time of XPCalendar when; false otherwise

Clear

public void Clear()
Clears the values of all the time fields.


Get

public int Get(int unit)
Gets the value for a given time field.

Parameters:
unit - Integer
Returns:
the value for the given time field

GetActualMaximum

public int GetActualMaximum(int unit)
Return the maximum value that this field could have, given the current date.

Parameters:
unit - Current Date
Returns:
the actual maximum for the unit

GetActualMinimum

public int GetActualMinimum(int unit)
Return the minimum value that this field could have, given the current date.

Parameters:
unit - Integer
Returns:
the actual minimum for the unit

GetFirstDayOfWeek

public int GetFirstDayOfWeek()
Gets the first day of the week; e.g., Sunday in US, Monday in France.

Returns:
the first day of the week

GetGregorianChange

public XPDateTime GetGregorianChange()
Gets the Gregorian Calendar change date. This is the point when the switch from Julian dates to Gregorian dates occurred. Default is October 15, 1582. Previous to this, dates will be in the Julian calendar.

Returns:
the Gregorian cutover date for this calendar

GetMaximum

public int GetMaximum(int unit)
Gets the maximum value for the given time field.

Parameters:
unit - value for the given time field
Returns:
the maximum for the unit

GetMinimum

public int GetMinimum(int unit)
Gets the minimum value for the given time field.

Parameters:
unit - time field
Returns:
the minimum for the unit

GetTime

public XPDateTime GetTime()
Gets this Calendar's current time.

Returns:
An instance of XPDateTime

GetTimeZone

public XPTimeZone GetTimeZone()
Gets the time zone.

Returns:
the time zone object associated with this calendar

GetUnderlyingObject

public java.util.GregorianCalendar GetUnderlyingObject()
Returns the platform specific object that this class wraps.

Returns:
An instance of GregorianCalendar class

Set

public void Set(int unit,
                int value)
Sets the time field with the given value.

Parameters:
unit - time
value - given

Set

public void Set(int year,
                int month,
                int day)
Sets the values for the fields year, month, and day.

Parameters:
year - yyyy
month - (1-12)
day - (1-31)

Set

public void Set(int year,
                int month,
                int day,
                int hour,
                int minute)
Sets the values for the fields year, month, day, hour, and minute.

Parameters:
year - yyyy
month - (1-12)
day - (1-31)
hour - (0-23)
minute - (0-59)

Set

public void Set(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second)
Sets the values for the fields year, month, day, hour, minute, and second.

Parameters:
year - yyyy
month - (1-12)
day - (1-31)
hour - (0-23)
minute - (0-59)
second - (0-59)

SetTime

public void SetTime(XPDateTime date)
Sets this Calendar's current time with the given XPDateTime.

Parameters:
date - DateTime Value.

SetTimeZone

public void SetTimeZone(XPTimeZone timezone)
Sets the timezone for the calendar.

Parameters:
timezone - Instance of XPTimeZone

ToString

public java.lang.String ToString()
Returns string representation of this XPCalendar.

Returns:
a string representation of this calendar

toString

public java.lang.String toString()
Returns string representation of this XPCalendar forwarding from ToString().

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this calendar


Copyright © 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.