|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.programix.time.DateTimeRange
public final class DateTimeRange
Immutable encapsulation of a period of time as expressed by a starting
DateTime and an ending DateTime. Either the starting
date or the ending date or both can be null.
If you need a date span that does not include any time-of-day and/or
time zone information, see PlainDateRange.
DateTools has handy utilities for formatting and parsing
DateTime instances to and from more human-readable Strings.
DateTime,
PlainDate,
PlainDateRange,
Serialized Form| Field Summary | |
|---|---|
static DateTimeRange |
BOTH_OPEN
This DateTimeRange has both an undefined start and an undefined end. |
static Comparator<DateTimeRange> |
NEWEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "newest" or "most recent" first. |
static Comparator<DateTimeRange> |
OLDEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "oldest" first. |
static DateTime |
OPEN
This constant can be used to specify that either the start or end of of the range is "open" (that is, it is not defined and can be considered to stretch out to infinity). |
| Constructor Summary | |
|---|---|
DateTimeRange(DateTime start,
DateTime end)
Creates a new instance with the specified start and end times. |
|
| Method Summary | |
|---|---|
Object |
clone()
Simply returns a reference to this instance. |
int |
compareTo(DateTimeRange otherRange)
Compares this instance to otherRange as defined by OLDEST_FIRST_COMPARATOR. |
boolean |
contains(DateTime dateTime)
Returns true if the specified DateTime falls within this range (inclusive of both endpoints). |
static DateTimeRange |
createLocal(String start,
String end)
Creates a new instance with the specified start and end times parsed using the local timezone. |
static DateTimeRange |
createUTC(String start,
String end)
Creates a new instance with the specified start and end times parsed using the UTC timezone. |
static DateTimeRange |
createWithOpenEnd(DateTime start)
Creates a new instance with an open end time and the specified start time. |
static DateTimeRange |
createWithOpenStart(DateTime end)
Creates a new instance with an open start and the specified end date. |
boolean |
equals(DateTimeRange otherDateTime)
Returns true if this instance's start and end dates exactly match the start and end dates of the passed instance. |
boolean |
equals(Object obj)
Returns true if this instance's start and end dates exactly match the start and end dates of the passed instance. |
DateTime |
forceIntoRange(DateTime value)
Forces the specified DateTime into this range. |
DateTime |
getEnd()
Returns the end of this range. |
Value |
getEndValue()
Returns the end of this range as a Value. |
DateTime |
getStart()
Returns the start of this range. |
Value |
getStartValue()
Returns the start of this range as a Value. |
boolean |
hasDefinedEnd()
Returns true if this range has a defined end date. |
boolean |
hasDefinedStart()
Returns true if this range has a defined start date. |
int |
hashCode()
|
DateTimeRange |
setEnd(DateTime newEnd)
Returns a new instance with the specified newEnd date and this instance's start date. |
DateTimeRange |
setStart(DateTime newStart)
Returns a new instance with the specified start date and this instance's end time. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final DateTime OPEN
public static final DateTimeRange BOTH_OPEN
DateTimeRange are immutable. In addition, there is no
need to create any other instances that have both ends open
(although is it permissible to create those instances).
public static final Comparator<DateTimeRange> OLDEST_FIRST_COMPARATOR
Comparator (time-of-date is not shown for simplicity):
open to 1997-02-02
open to 1997-09-09
open to 2000-02-02
open to 2000-03-03
open to open
1997-02-02 to 1997-02-02
1997-02-03 to 1997-02-03
1997-06-06 to 1997-09-09
1997-06-06 to 1997-10-10
1997-06-06 to open
1997-07-07 to 1997-08-08
1997-08-08 to 1997-09-09
1997-08-08 to open
1997-09-09 to open
Also see NEWEST_FIRST_COMPARATOR is it is not simply
the reverse of this comparator.
For additional permutations, see NullFirstComparator,
NullLastComparator, and ReverseComparator.
public static final Comparator<DateTimeRange> NEWEST_FIRST_COMPARATOR
Comparator (time-of-date is not shown for simplicity):
1997-09-09 to open
1997-08-08 to open
1997-06-06 to open
open to open
open to 2000-03-03
open to 2000-02-02
1997-06-06 to 1997-10-10
1997-08-08 to 1997-09-09
1997-06-06 to 1997-09-09
open to 1997-09-09
1997-07-07 to 1997-08-08
1997-02-03 to 1997-02-03
1997-02-02 to 1997-02-02
open to 1997-02-02
Also see OLDEST_FIRST_COMPARATOR is it is not simply
the reverse of this comparator.
For additional permutations, see NullFirstComparator,
NullLastComparator, and ReverseComparator.
| Constructor Detail |
|---|
public DateTimeRange(DateTime start,
DateTime end)
throws IllegalArgumentException
OPEN (or null)
can be used to indicate that one end or the other is open-ended.
Both the start and the end can be open, and if
you prefer, there is a shared, immutable instance that can be
used instead: BOTH_OPEN.
start - the beginning of the range. Use OPEN
or null to indicate that the range is open-ended and has
no starting time.end - the ending of the range. Use OPEN
or null to indicate that the range is open-ended and has
no end time.
IllegalArgumentException - if the start time
comes after the end time.createLocal(String, String),
createUTC(String, String)| Method Detail |
|---|
public static DateTimeRange createLocal(String start,
String end)
throws IllegalArgumentException,
DateTimeException
empty string
to indicate that one end or the other (or both) is open-ended.
start - the beginning of the time range.
Use null or an empty string
to indicate that the range is open-ended and has no starting time.end - the ending of the time range.
Use null or an empty string
to indicate that the range is open-ended and has no ending time.
IllegalArgumentException - if the start time
comes after the end time.
DateTimeException - if either String can not be
parsed as a DateTime.createUTC(String, String),
DateTimeRange(DateTime, DateTime),
DateTools.parseLocal(String)
public static DateTimeRange createUTC(String start,
String end)
throws IllegalArgumentException,
DateTimeException
empty string
to indicate that one end or the other (or both) is open-ended.
You can also use a Value who's isEmpty()
method returns true to indicate that one end or the other
(or both) is open-ended.
start - the beginning of the time range.
Use null or an empty string
to indicate that the range is open-ended and has no starting time.end - the ending of the time range.
Use null or an empty string
to indicate that the range is open-ended and has no ending time.
IllegalArgumentException - if the start time
comes after the end time.
DateTimeException - if either String can not be
parsed as a DateTime.createLocal(String, String),
DateTimeRange(DateTime, DateTime),
DateTools.parseUTC(String)public static DateTimeRange createWithOpenStart(DateTime end)
end - the end of the date range.public static DateTimeRange createWithOpenEnd(DateTime start)
start - the start of the date range.
public DateTimeRange setStart(DateTime newStart)
throws IllegalArgumentException
newStart - the new start date for the new instance or null.
IllegalArgumentException - if the start comes after the end.DateTimeRange(DateTime, DateTime)
public DateTimeRange setEnd(DateTime newEnd)
throws IllegalArgumentException
newEnd - the new end date for the new instance or null.
IllegalArgumentException - if the start comes after the end.DateTimeRange(DateTime, DateTime)public boolean hasDefinedStart()
getStart()public DateTime getStart()
OPEN
(null) is returned.
hasDefinedStart(),
getStartValue()public Value getStartValue()
hasDefinedStart(),
getStart()public boolean hasDefinedEnd()
getEnd()public DateTime getEnd()
OPEN
(null) is returned.
hasDefinedEnd()public Value getEndValue()
hasDefinedEnd(),
getEnd()public boolean contains(DateTime dateTime)
public DateTime forceIntoRange(DateTime value)
throws IllegalArgumentException
contains(DateTime)), then the passed date
is simply returned (no forcing is necessary).
If the range has a defined start and the specified date comes
before that start, then the start is returned.
If the range has a defined end and the specified date comes
after that end, then the end is returned.
value - the date to force into this range.
IllegalArgumentException - if the specified date is null.
public int compareTo(DateTimeRange otherRange)
throws IllegalArgumentException
OLDEST_FIRST_COMPARATOR.
compareTo in interface Comparable<DateTimeRange>IllegalArgumentException - if null if passed.public boolean equals(DateTimeRange otherDateTime)
public boolean equals(Object obj)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Objectpublic Object clone()
clone in class Object
|
ProgramixGenericLib v5.0.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||