public class Period<T extends Temporal> extends Object implements Comparable<Period<T>>, Serializable
CalendarDateFormat.
NOTE: End dates and durations are implicitly derived when not explicitly specified. This means that you cannot
rely on the returned values from the getters to deduce whether a period has an explicit end date or duration.
3.3.9. Period of Time
Value Name: PERIOD
Purpose: This value type is used to identify values that contain a
precise period of time.
Format Definition: This value type is defined by the following
notation:
period = period-explicit / period-start
period-explicit = date-time "/" date-time
; [ISO.8601.2004] complete representation basic format for a
; period of time consisting of a start and end. The start MUST
; be before the end.
period-start = date-time "/" dur-value
; [ISO.8601.2004] complete representation basic format for a
; period of time consisting of a start and positive duration
; of time.
Description: If the property permits, multiple "period" values are
specified by a COMMA-separated list of values. There are two
forms of a period of time. First, a period of time is identified
by its start and its end. This format is based on the
[ISO.8601.2004] complete representation, basic format for "DATE-
TIME" start of the period, followed by a SOLIDUS character
followed by the "DATE-TIME" of the end of the period. The start
of the period MUST be before the end of the period. Second, a
period of time can also be defined by a start and a positive
duration of time. The format is based on the [ISO.8601.2004]
complete representation, basic format for the "DATE-TIME" start of
the period, followed by a SOLIDUS character, followed by the
[ISO.8601.2004] basic format for "DURATION" of the period.
Example: The period starting at 18:00:00 UTC, on January 1, 1997 and
ending at 07:00:00 UTC on January 2, 1997 would be:
19970101T180000Z/19970102T070000Z
The period start at 18:00:00 on January 1, 1997 and lasting 5
hours and 30 minutes would be:
19970101T180000Z/PT5H30M
No additional content value encoding (i.e., BACKSLASH character
encoding, see Section 3.3.11) is defined for this value type.
| Constructor and Description |
|---|
Period(DateTime start,
Dur duration)
Deprecated.
|
Period(T start,
T end)
Constructs a new period with the specified start and end date.
|
Period(T start,
T end,
CalendarDateFormat dateFormat)
Constructs a new period with the specified start and end date with a common date format.
|
Period(T start,
TemporalAmount duration)
Constructs a new period with the specified start date and duration.
|
Period(T start,
TemporalAmount duration,
CalendarDateFormat dateFormat) |
| Modifier and Type | Method and Description |
|---|---|
Period<T> |
add(Period<T> period)
Creates a period that encompasses both this period and another one.
|
int |
compareTo(Period<T> period)
Compares the specified period with this period.
|
boolean |
equals(Object o) |
Component |
getComponent() |
TemporalAmount |
getDuration()
Returns the duration of this period.
|
T |
getEnd()
Returns the end date of this period.
|
T |
getStart() |
int |
hashCode() |
boolean |
includes(Date date,
boolean inclusive)
Deprecated.
use
includes(Temporal) instead. |
boolean |
includes(Temporal date)
Determines if the specified date occurs within this period (inclusive of
period start and end).
|
boolean |
intersects(Period<?> other)
Decides whether this period intersects with another one.
|
boolean |
isEmpty()
An empty period is one that consumes no time.
|
static <T extends Temporal> |
parse(String value)
Parse a string representation of a period.
|
void |
setComponent(Component component) |
PeriodList<T> |
subtract(Period<T> period)
Creates a set of periods resulting from the subtraction of the specified
period from this one.
|
org.threeten.extra.Interval |
toInterval() |
org.threeten.extra.Interval |
toInterval(ZoneId zoneId) |
String |
toString()
Formats the period as an iCalendar compatible string.
|
String |
toString(ZoneId zoneId)
Formats the period as an iCalendar compatible string in the specified timezone.
|
public Period(T start, T end)
start - the start date of the periodend - the end date of the periodpublic Period(T start, T end, CalendarDateFormat dateFormat)
start - the start date of the periodend - the end date of the perioddateFormat - the format used to generate string representations@Deprecated public Period(DateTime start, Dur duration)
start - the start date of the periodduration - the duration of the periodpublic Period(T start, TemporalAmount duration)
start - the start date of the periodduration - the duration of the periodpublic Period(T start, TemporalAmount duration, CalendarDateFormat dateFormat)
public static <T extends Temporal> Period<T> parse(String value)
T - the expected temporal type of the resulting periodvalue - a string representation of a periodDateTimeParseException - if the text cannot be parsed to a periodpublic final TemporalAmount getDuration()
public final T getEnd()
public final T getStart()
@Deprecated public final boolean includes(Date date, boolean inclusive)
includes(Temporal) instead.date - a date to test for inclusioninclusive - indicates if the start and end of the period are included in the testpublic final boolean includes(Temporal date)
date - a date to test for inclusionpublic final Period<T> add(Period<T> period)
period - the period to add to this onepublic final PeriodList<T> subtract(Period<T> period)
period - a period to subtract from this onepublic final boolean isEmpty()
public String toString()
public String toString(ZoneId zoneId)
public boolean intersects(Period<?> other)
other - a possible intersecting periodpublic org.threeten.extra.Interval toInterval()
public org.threeten.extra.Interval toInterval(ZoneId zoneId)
public final int compareTo(Period<T> period)
compareTo in interface Comparable<Period<T extends Temporal>>period - a period to compare with this onepublic Component getComponent()
public void setComponent(Component component)