java.lang.Object
net.fortuna.ical4j.model.Period<T>
- All Implemented Interfaces:
Serializable,Comparable<Period<T>>
public class Period<T extends Temporal>
extends Object
implements Comparable<Period<T>>, Serializable
$Id$ [Apr 14, 2004]
Defines a period of time. A period may be specified as either a start date and end date,
or a start date and duration. This class enforces a consistent string representation of start date and
(where specified) end date via a common
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.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Period(T start, TemporalAmount duration) Constructs a new period with the specified start date and duration.Period(T start, TemporalAmount duration, CalendarDateFormat dateFormat) 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. -
Method Summary
Modifier and TypeMethodDescriptionCreates a period that encompasses both this period and another one.final intCompares the specified period with this period.booleanfinal TemporalAmountReturns the duration of this period.final TgetEnd()Returns the end date of this period.final TgetStart()inthashCode()final booleanDetermines if the specified date occurs within this period (inclusive of period start and end).final booleanDeprecated.booleanintersects(Period<?> other) Decides whether this period intersects with another one.final booleanisEmpty()An empty period is one that consumes no time.Parse a string representation of a period.voidsetComponent(Component component) final PeriodList<T>Creates a set of periods resulting from the subtraction of the specified period from this one.org.threeten.extra.Intervalorg.threeten.extra.IntervaltoInterval(ZoneId zoneId) toString()Formats the period as an iCalendar compatible string.Formats the period as an iCalendar compatible string in the specified timezone.
-
Constructor Details
-
Period
Constructs a new period with the specified start and end date.- Parameters:
start- the start date of the periodend- the end date of the period
-
Period
Constructs a new period with the specified start and end date with a common date format.- Parameters:
start- the start date of the periodend- the end date of the perioddateFormat- the format used to generate string representations
-
Period
Deprecated.Constructs a new period with the specified start date and duration.- Parameters:
start- the start date of the periodduration- the duration of the period
-
Period
Constructs a new period with the specified start date and duration.- Parameters:
start- the start date of the periodduration- the duration of the period
-
Period
-
-
Method Details
-
parse
Parse a string representation of a period.- Type Parameters:
T- the expected temporal type of the resulting period- Parameters:
value- a string representation of a period- Returns:
- a new period instance
- Throws:
DateTimeParseException- if the text cannot be parsed to a period
-
getDuration
Returns the duration of this period. If an explicit duration is not specified, the duration is derived from the end date.- Returns:
- the duration of this period in milliseconds.
-
getEnd
Returns the end date of this period. If an explicit end date is not specified, the end date is derived from the duration.- Returns:
- the end date of this period.
-
getStart
- Returns:
- Returns the start.
-
includes
Deprecated.useincludes(Temporal)instead.- Parameters:
date- a date to test for inclusioninclusive- indicates if the start and end of the period are included in the test- Returns:
- true if the specified date occurs within the current period
-
includes
Determines if the specified date occurs within this period (inclusive of period start and end).- Parameters:
date- a date to test for inclusion- Returns:
- true if the specified date occurs within the current period
-
add
Creates a period that encompasses both this period and another one. If the other period is null, return a copy of this period. NOTE: Resulting periods are specified by explicitly setting a start date and end date (i.e. durations are implied).- Parameters:
period- the period to add to this one- Returns:
- a period
-
subtract
Creates a set of periods resulting from the subtraction of the specified period from this one. If the specified period is completely contained in this period, the resulting list will contain two periods. Otherwise it will contain one. If the specified period does not intersect this period a list containing this period is returned. If this period is completely contained within the specified period an empty period list is returned.- Parameters:
period- a period to subtract from this one- Returns:
- a list containing zero, one or two periods.
-
isEmpty
public final boolean isEmpty()An empty period is one that consumes no time.- Returns:
- true if this period consumes no time, otherwise false
-
toString
Formats the period as an iCalendar compatible string. NOTE: Where a period represents floating date/time values the default local timezone is applied prior to formatting. -
toString
Formats the period as an iCalendar compatible string in the specified timezone.- Returns:
- a string representation of the period as applied in the specified timezone
-
intersects
Decides whether this period intersects with another one.- Parameters:
other- a possible intersecting period- Returns:
- true if the specified period intersects this one, false otherwise.
-
toInterval
public org.threeten.extra.Interval toInterval() -
toInterval
-
compareTo
Compares the specified period with this period. First, compare the start dates. If they are the same, compare the end dates.- Specified by:
compareToin interfaceComparable<T extends Temporal>- Parameters:
period- a period to compare with this one- Returns:
- a postive value if this period is greater, negative if the other is greater, or zero if they are equal
-
equals
-
hashCode
public int hashCode() -
getComponent
-
setComponent
-
includes(Temporal)instead.