public class DateRange extends Object implements Serializable
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.Modifier and Type | Field and Description |
---|---|
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 Calendar |
controlCalendar
Calendar to use when no date is set.
|
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<String> |
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
static void |
assertFalse(String msg,
boolean val) |
static void |
assertTrue(String msg,
boolean val) |
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) |
protected Calendar |
getControlCalendar(FacesContext context) |
Date |
getDate()
Fixed date.
|
long |
getFixedRange()
Fixed range in milliseconds.
|
String |
getRelativeRange()
Relative range, an enumerated value.
|
boolean |
isEmpty()
Determine if this date range is empty and doesn't represent any actual date range
|
boolean |
isSet()
Determine if this date range presents an actual date range is not empty
|
static void |
main(String[] args) |
void |
setControlCalendar(Calendar calendar)
Set a calendar to be used for relative ranges.
|
void |
setDate(Date date)
Fixed date.
|
void |
setFixedRange(long fixedRange)
Fixed range in milliseconds.
|
void |
setRelativeRange(String relativeRange)
Relative range, an enumerated value.
|
public static final Date BEGINNING_OF_TIME
public static final Date END_OF_TIME
public static final String FIXED
public static final String PREVIOUS_DAY
public static final String PREVIOUS_WEEK
public static final String PREVIOUS_MONTH
public static final String PREVIOUS_YEAR
public static final String THIS_DAY
public static final String THIS_WEEK
public static final String THIS_MONTH
public static final String THIS_YEAR
public static final String NEXT_DAY
public static final String NEXT_WEEK
public static final String NEXT_MONTH
public static final String NEXT_YEAR
protected long fixedRange
relativeRange
is not FIXED
, this must be zero.protected String relativeRange
FIXED
,
THIS_DAY
, PREVIOUS_DAY
,
THIS_WEEK
, PREVIOUS_WEEK
,
THIS_MONTH
, PREVIOUS_MONTH
,
THIS_YEAR
, or PREVIOUS_YEAR
.
If fixedRange
is not zero, this must be FIXED
.protected Date date
relativeRange
is FIXED
, this is the range's end.protected Calendar controlCalendar
public DateRange()
public DateRange(long fixedRange)
fixedRange
- Fixed range in milliseconds.public DateRange(long fixedRange, Date date)
fixedRange
- Fixed range in milliseconds.date
- Fixed date. May be null (meaning no fixed date).public DateRange(String relativeRange)
FIXED
,
THIS_DAY
, PREVIOUS_DAY
,
THIS_WEEK
, PREVIOUS_WEEK
,
THIS_MONTH
, PREVIOUS_MONTH
,
THIS_YEAR
, or PREVIOUS_YEAR
.
If fixedRange
is not zero, this must be FIXED
.relativeRange
- Relative range, an enumerated value.public Date calculateStart()
BEGINNING_OF_TIME
if no start date or range is infinite.public Date calculateStart(FacesContext context)
context
- Current user context.BEGINNING_OF_TIME
if no start date or range is infinite.public Date calculateStart(FacesContext context, Calendar calendar)
context
- Current user context.calendar
- the calendar to use pre-initialized to the correct timezoneBEGINNING_OF_TIME
if no start date or range is infinite.public Date calculateEnd()
END_OF_TIME
if no end date or range is infinite.public Date calculateEnd(FacesContext context)
context
- Current user context.END_OF_TIME
if no end date or range is infinite.public Date calculateEnd(FacesContext context, Calendar calendar)
context
- Current user context.calendar
- the calendar to use pre-initialized to the correct timezoneEND_OF_TIME
if no end date or range is infinite.public long getFixedRange()
relativeRange
is not FIXED
, this must be zero.public void setFixedRange(long fixedRange)
relativeRange
is not FIXED
, this must be zero.fixedRange
- Fixed range in milliseconds.public String getRelativeRange()
FIXED
,
THIS_DAY
, PREVIOUS_DAY
,
THIS_WEEK
, PREVIOUS_WEEK
,
THIS_MONTH
, PREVIOUS_MONTH
,
THIS_YEAR
, or PREVIOUS_YEAR
.
If fixedRange
is not zero, this must be FIXED
.public void setRelativeRange(String relativeRange)
FIXED
,
THIS_DAY
, PREVIOUS_DAY
,
THIS_WEEK
, PREVIOUS_WEEK
,
THIS_MONTH
, PREVIOUS_MONTH
,
THIS_YEAR
, or PREVIOUS_YEAR
.
If fixedRange
is not zero, this must be FIXED
.relativeRange
- Relative range, an enumerated value.public Date getDate()
relativeRange
is FIXED
, this is the range's end.public void setDate(Date date)
relativeRange
is FIXED
, this is the range's end.Fixed
- date. May be null (meaning no fixed date).public boolean isSet()
public boolean isEmpty()
protected Calendar getControlCalendar(FacesContext context)
public void setControlCalendar(Calendar calendar)
calendar
- optional calendar to use in relative range calculationspublic static void main(String[] args)
public static void assertTrue(String msg, boolean val)
public static void assertFalse(String msg, boolean val)