Class DateRange
java.lang.Object
com.webmethods.caf.faces.data.object.DateRange
- All Implemented Interfaces:
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
getFixedRange()
is zero, getRelativeRange()
is FIXED
,
and getDate()
is null, the period of time is infinite,
and the calculated start and end dates will be null.
If getFixedRange()
is Long.MAX_VALUE
and getRelativeRange()
is FIXED
,
then the period of time stretches from the specified date to the end of time.
If getFixedRange()
is Long.MIN_VALUE
and getRelativeRange()
is FIXED
,
then the period of time stretches from the beginning of time to the specified date.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Date
Date representing the beginning of time BEGINNING_OF_TIME set to "the epoch", namely January 1, 1970, 00:00:00 GMTprotected Calendar
Calendar to use when no date is set.protected Date
Fixed date.static final Date
Date representing the end of time END_OF_TIME set to 31-Dec-2099static final String
Fixed range.protected long
Fixed range in milliseconds.static final String
Relative range: tomorrow.static final String
Relative range: next month.static final String
Relative range: next week.static final String
Relative range: next year.static final String
Relative range: yesterday.static final String
Relative range: previous month.static final String
Relative range: previous week.static final String
Relative range: previous year.Set of valid relative ranges.protected String
Relative range, an enumerated value.static final String
Relative range: today.static final String
Relative range: this month.static final String
Relative range: this week.static final String
Relative range: this year. -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.Creates a new date range with the specified fixed length and date.Creates a new date range with the specified relative length. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertFalse
(String msg, boolean val) static void
assertTrue
(String msg, boolean val) 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.calculateEnd
(FacesContext context) Calculates range end, with regard to range's fixed date (or the current date, if the range has no fixed 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).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.calculateStart
(FacesContext context) Calculates range start, with regard to range's fixed date (or the current date, if the range has no fixed 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
protected Calendar
getControlCalendar
(FacesContext context) getDate()
Fixed date.long
Fixed range in milliseconds.Relative range, an enumerated value.boolean
isEmpty()
Determine if this date range is empty and doesn't represent any actual date rangeboolean
isSet()
Determine if this date range presents an actual date range is not emptystatic void
void
setControlCalendar
(Calendar calendar) Set a calendar to be used for relative ranges.void
Fixed date.void
setFixedRange
(long fixedRange) Fixed range in milliseconds.void
setRelativeRange
(String relativeRange) Relative range, an enumerated value.
-
Field Details
-
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
Date representing the end of time END_OF_TIME set to 31-Dec-2099 -
FIXED
Fixed range.- See Also:
-
PREVIOUS_DAY
Relative range: yesterday.- See Also:
-
PREVIOUS_WEEK
Relative range: previous week.- See Also:
-
PREVIOUS_MONTH
Relative range: previous month.- See Also:
-
PREVIOUS_YEAR
Relative range: previous year.- See Also:
-
THIS_DAY
Relative range: today.- See Also:
-
THIS_WEEK
Relative range: this week.- See Also:
-
THIS_MONTH
Relative range: this month.- See Also:
-
THIS_YEAR
Relative range: this year.- See Also:
-
NEXT_DAY
Relative range: tomorrow.- See Also:
-
NEXT_WEEK
Relative range: next week.- See Also:
-
NEXT_MONTH
Relative range: next month.- See Also:
-
NEXT_YEAR
Relative range: next year.- See Also:
-
RELATIVE_RANGES
Set of valid relative ranges. -
fixedRange
protected long fixedRangeFixed range in milliseconds. IfrelativeRange
is notFIXED
, this must be zero. -
relativeRange
Relative range, an enumerated value. Must be eitherFIXED
,THIS_DAY
,PREVIOUS_DAY
,THIS_WEEK
,PREVIOUS_WEEK
,THIS_MONTH
,PREVIOUS_MONTH
,THIS_YEAR
, orPREVIOUS_YEAR
. IffixedRange
is not zero, this must beFIXED
. -
date
Fixed date. May be null (meaning no fixed date). IfrelativeRange
isFIXED
, this is the range's end. -
controlCalendar
Calendar to use when no date is set. May be null (user's calendar will be used).
-
-
Constructor Details
-
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
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
Creates a new date range with the specified relative length. Must be eitherFIXED
,THIS_DAY
,PREVIOUS_DAY
,THIS_WEEK
,PREVIOUS_WEEK
,THIS_MONTH
,PREVIOUS_MONTH
,THIS_YEAR
, orPREVIOUS_YEAR
. IffixedRange
is not zero, this must beFIXED
.- Parameters:
relativeRange
- Relative range, an enumerated value.
-
-
Method Details
-
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.
BEGINNING_OF_TIME
if no start date or range is infinite.
-
calculateStart
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.
BEGINNING_OF_TIME
if no start date or range is infinite.
-
calculateStart
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.
BEGINNING_OF_TIME
if no start date or range is infinite.
-
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.
END_OF_TIME
if no end date or range is infinite.
-
calculateEnd
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.
END_OF_TIME
if no end date or range is infinite.
-
calculateEnd
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.
END_OF_TIME
if no end date or range is infinite.
-
getFixedRange
public long getFixedRange()Fixed range in milliseconds. IfrelativeRange
is notFIXED
, this must be zero.- Returns:
- Fixed range in milliseconds.
-
setFixedRange
public void setFixedRange(long fixedRange) Fixed range in milliseconds. IfrelativeRange
is notFIXED
, this must be zero.- Parameters:
fixedRange
- Fixed range in milliseconds.
-
getRelativeRange
Relative range, an enumerated value. Must be eitherFIXED
,THIS_DAY
,PREVIOUS_DAY
,THIS_WEEK
,PREVIOUS_WEEK
,THIS_MONTH
,PREVIOUS_MONTH
,THIS_YEAR
, orPREVIOUS_YEAR
. IffixedRange
is not zero, this must beFIXED
.- Returns:
- Relative range, an enumerated value.
-
setRelativeRange
Relative range, an enumerated value. Must be eitherFIXED
,THIS_DAY
,PREVIOUS_DAY
,THIS_WEEK
,PREVIOUS_WEEK
,THIS_MONTH
,PREVIOUS_MONTH
,THIS_YEAR
, orPREVIOUS_YEAR
. IffixedRange
is not zero, this must beFIXED
.- Parameters:
relativeRange
- Relative range, an enumerated value.
-
getDate
Fixed date. May be null (meaning no fixed date). IfrelativeRange
isFIXED
, this is the range's end.- Returns:
- Fixed date. May be null (meaning no fixed date).
-
setDate
Fixed date. May be null (meaning no fixed date). IfrelativeRange
isFIXED
, this is the range's end.- Parameters:
Fixed
- date. May be null (meaning no fixed date).
-
isSet
public boolean isSet()Determine if this date range presents an actual date range is not empty- Returns:
-
isEmpty
public boolean isEmpty()Determine if this date range is empty and doesn't represent any actual date range- Returns:
-
equals
-
getControlCalendar
-
setControlCalendar
Set a calendar to be used for relative ranges. If no calendar is set, user's calendar will be used.- Parameters:
calendar
- optional calendar to use in relative range calculations
-
main
-
assertTrue
-
assertFalse
-