com.webmethods.caf.faces.data.object
Class DateRange

java.lang.Object
  extended by com.webmethods.caf.faces.data.object.DateRange
All Implemented Interfaces:
Serializable

public class DateRange
extends Object
implements Serializable

Represents a period of time, optionally with regard to a fixed date. The period of time (the "range") may be a fixed number of milliseconds, a relative span ("today", "yesterday", etc.), or infinite (no start or end). If the period of time is a fixed positive number of milliseconds, the fixed date is the range's start. If the period of time is a fixed negative number of milliseconds, the fixed date is the range's end. If DateRange.getFixedRange() is zero, DateRange.getRelativeRange() is DateRange.FIXED, and DateRange.getDate() is null, the period of time is infinite, and the calculated start and end dates will be null. If DateRange.getFixedRange() is Long.MAX_VALUE and DateRange.getRelativeRange() is DateRange.FIXED, then the period of time stretches from the specified date to the end of time. If DateRange.getFixedRange() is Long.MIN_VALUE and DateRange.getRelativeRange() is DateRange.FIXED, then the period of time stretches from the beginning of time to the specified date.

See Also:
Serialized Form

Field Summary
static Date BEGINNING_OF_TIME
          Date representing the beginning of time BEGINNING_OF_TIME set to "the epoch", namely January 1, 1970, 00:00:00 GMT
protected  Date date
          Fixed date.
static Date END_OF_TIME
          Date representing the end of time END_OF_TIME set to 31-Dec-2099
static String FIXED
          Fixed range.
protected  long fixedRange
          Fixed range in milliseconds.
static String NEXT_DAY
          Relative range: tomorrow.
static String NEXT_MONTH
          Relative range: next month.
static String NEXT_WEEK
          Relative range: next week.
static String NEXT_YEAR
          Relative range: next year.
static String PREVIOUS_DAY
          Relative range: yesterday.
static String PREVIOUS_MONTH
          Relative range: previous month.
static String PREVIOUS_WEEK
          Relative range: previous week.
static String PREVIOUS_YEAR
          Relative range: previous year.
protected static Set RELATIVE_RANGES
          Set of valid relative ranges.
protected  String relativeRange
          Relative range, an enumerated value.
static String THIS_DAY
          Relative range: today.
static String THIS_MONTH
          Relative range: this month.
static String THIS_WEEK
          Relative range: this week.
static String THIS_YEAR
          Relative range: this year.
 
Constructor Summary
DateRange()
          Creates a new (infinite) date range with a fixed length of zero and no fixed date.
DateRange(long fixedRange)
          Creates a new date range with the specified fixed length and no fixed date.
DateRange(long fixedRange, Date date)
          Creates a new date range with the specified fixed length and date.
DateRange(String relativeRange)
          Creates a new date range with the specified relative length.
 
Method Summary
 Date calculateEnd()
          Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date) for the current user context.
 Date calculateEnd(FacesContext context)
          Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date).
 Date calculateEnd(FacesContext context, Calendar calendar)
          Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date).
 Date calculateStart()
          Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date) for the current user context.
 Date calculateStart(FacesContext context)
          Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date).
 Date calculateStart(FacesContext context, Calendar calendar)
          Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date).
 boolean equals(Object obj)
           
 Date getDate()
          Fixed date.
 long getFixedRange()
          Fixed range in milliseconds.
 String getRelativeRange()
          Relative range, an enumerated value.
 void setDate(Date date)
          Fixed date.
 void setFixedRange(long fixedRange)
          Fixed range in milliseconds.
 void setRelativeRange(String relativeRange)
          Relative range, an enumerated value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEGINNING_OF_TIME

public static final Date BEGINNING_OF_TIME
Date representing the beginning of time BEGINNING_OF_TIME set to "the epoch", namely January 1, 1970, 00:00:00 GMT


END_OF_TIME

public static final Date END_OF_TIME
Date representing the end of time END_OF_TIME set to 31-Dec-2099


FIXED

public static final String FIXED
Fixed range.

See Also:
Constant Field Values

PREVIOUS_DAY

public static final String PREVIOUS_DAY
Relative range: yesterday.

See Also:
Constant Field Values

PREVIOUS_WEEK

public static final String PREVIOUS_WEEK
Relative range: previous week.

See Also:
Constant Field Values

PREVIOUS_MONTH

public static final String PREVIOUS_MONTH
Relative range: previous month.

See Also:
Constant Field Values

PREVIOUS_YEAR

public static final String PREVIOUS_YEAR
Relative range: previous year.

See Also:
Constant Field Values

THIS_DAY

public static final String THIS_DAY
Relative range: today.

See Also:
Constant Field Values

THIS_WEEK

public static final String THIS_WEEK
Relative range: this week.

See Also:
Constant Field Values

THIS_MONTH

public static final String THIS_MONTH
Relative range: this month.

See Also:
Constant Field Values

THIS_YEAR

public static final String THIS_YEAR
Relative range: this year.

See Also:
Constant Field Values

NEXT_DAY

public static final String NEXT_DAY
Relative range: tomorrow.

See Also:
Constant Field Values

NEXT_WEEK

public static final String NEXT_WEEK
Relative range: next week.

See Also:
Constant Field Values

NEXT_MONTH

public static final String NEXT_MONTH
Relative range: next month.

See Also:
Constant Field Values

NEXT_YEAR

public static final String NEXT_YEAR
Relative range: next year.

See Also:
Constant Field Values

RELATIVE_RANGES

protected static Set RELATIVE_RANGES
Set of valid relative ranges.


fixedRange

protected long fixedRange
Fixed range in milliseconds. If DateRange.relativeRange is not DateRange.FIXED, this must be zero.


relativeRange

protected String relativeRange
Relative range, an enumerated value. Must be either DateRange.FIXED, DateRange.THIS_DAY, DateRange.PREVIOUS_DAY, DateRange.THIS_WEEK, DateRange.PREVIOUS_WEEK, DateRange.THIS_MONTH, DateRange.PREVIOUS_MONTH, DateRange.THIS_YEAR, or DateRange.PREVIOUS_YEAR. If DateRange.fixedRange is not zero, this must be DateRange.FIXED.


date

protected Date date
Fixed date. May be null (meaning no fixed date). If DateRange.relativeRange is DateRange.FIXED, this is the range's end.

Constructor Detail

DateRange

public DateRange()
Creates a new (infinite) date range with a fixed length of zero and no fixed date.


DateRange

public DateRange(long fixedRange)
Creates a new date range with the specified fixed length and no fixed date.

Parameters:
fixedRange - Fixed range in milliseconds.

DateRange

public DateRange(long fixedRange,
                 Date date)
Creates a new date range with the specified fixed length and date.

Parameters:
fixedRange - Fixed range in milliseconds.
date - Fixed date. May be null (meaning no fixed date).

DateRange

public DateRange(String relativeRange)
Creates a new date range with the specified relative length. Must be either DateRange.FIXED, DateRange.THIS_DAY, DateRange.PREVIOUS_DAY, DateRange.THIS_WEEK, DateRange.PREVIOUS_WEEK, DateRange.THIS_MONTH, DateRange.PREVIOUS_MONTH, DateRange.THIS_YEAR, or DateRange.PREVIOUS_YEAR. If DateRange.fixedRange is not zero, this must be DateRange.FIXED.

Parameters:
relativeRange - Relative range, an enumerated value.
Method Detail

calculateStart

public Date calculateStart()
Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date) for the current user context. Takes in account the current user's calendar preferences.

Returns:
Calculated start date. DateRange.BEGINNING_OF_TIME if no start date or range is infinite.

calculateStart

public Date calculateStart(FacesContext context)
Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.

Parameters:
context - Current user context.
Returns:
Calculated start date. DateRange.BEGINNING_OF_TIME if no start date or range is infinite.

calculateStart

public Date calculateStart(FacesContext context,
                           Calendar calendar)
Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.

Parameters:
context - Current user context.
calendar - the calendar to use pre-initialized to the correct timezone
Returns:
Calculated start date. DateRange.BEGINNING_OF_TIME if no start date or range is infinite.

calculateEnd

public Date calculateEnd()
Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date) for the current user context. Takes in account the current user's calendar preferences.

Returns:
Calculated end date. DateRange.END_OF_TIME if no end date or range is infinite.

calculateEnd

public Date calculateEnd(FacesContext context)
Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.

Parameters:
context - Current user context.
Returns:
Calculated end date. DateRange.END_OF_TIME if no end date or range is infinite.

calculateEnd

public Date calculateEnd(FacesContext context,
                         Calendar calendar)
Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed date). Takes in account the current user's calendar preferences.

Parameters:
context - Current user context.
calendar - the calendar to use pre-initialized to the correct timezone
Returns:
Calculated end date. DateRange.END_OF_TIME if no end date or range is infinite.

getFixedRange

public long getFixedRange()
Fixed range in milliseconds. If DateRange.relativeRange is not DateRange.FIXED, this must be zero.

Returns:
Fixed range in milliseconds.

setFixedRange

public void setFixedRange(long fixedRange)
Fixed range in milliseconds. If DateRange.relativeRange is not DateRange.FIXED, this must be zero.

Parameters:
fixedRange - Fixed range in milliseconds.

getRelativeRange

public String getRelativeRange()
Relative range, an enumerated value. Must be either DateRange.FIXED, DateRange.THIS_DAY, DateRange.PREVIOUS_DAY, DateRange.THIS_WEEK, DateRange.PREVIOUS_WEEK, DateRange.THIS_MONTH, DateRange.PREVIOUS_MONTH, DateRange.THIS_YEAR, or DateRange.PREVIOUS_YEAR. If DateRange.fixedRange is not zero, this must be DateRange.FIXED.

Returns:
Relative range, an enumerated value.

setRelativeRange

public void setRelativeRange(String relativeRange)
Relative range, an enumerated value. Must be either DateRange.FIXED, DateRange.THIS_DAY, DateRange.PREVIOUS_DAY, DateRange.THIS_WEEK, DateRange.PREVIOUS_WEEK, DateRange.THIS_MONTH, DateRange.PREVIOUS_MONTH, DateRange.THIS_YEAR, or DateRange.PREVIOUS_YEAR. If DateRange.fixedRange is not zero, this must be DateRange.FIXED.

Parameters:
relativeRange - Relative range, an enumerated value.

getDate

public Date getDate()
Fixed date. May be null (meaning no fixed date). If DateRange.relativeRange is DateRange.FIXED, this is the range's end.

Returns:
Fixed date. May be null (meaning no fixed date).

setDate

public void setDate(Date date)
Fixed date. May be null (meaning no fixed date). If DateRange.relativeRange is DateRange.FIXED, this is the range's end.

Parameters:
Fixed - date. May be null (meaning no fixed date).

equals

public boolean equals(Object obj)
Overrides:
equals in class Object