net.fortuna.ical4j.model

## Class Period

- java.lang.Object
- - net.fortuna.ical4j.model.DateRange
  - - net.fortuna.ical4j.model.Period

All Implemented Interfaces:
  Serializable, Comparable

    public class Period
    extends DateRange
    implements Comparable

$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. 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.

Author:
  Ben Fortuna
See Also:
  Serialized Form

### Field Summary

### Fields inherited from class net.fortuna.ical4j.model.DateRange

`INCLUSIVE_END, INCLUSIVE_START`

### Constructor Summary

Constructors
Constructor and Description
`Period(DateTime start, DateTime end)` Constructs a new period with the specied start and end date.
`Period(DateTime start, Dur duration)` Constructs a new period with the specified start date and duration.
`Period(String aValue)` Constructor.

### Method Summary

Methods
`Period` `add(Period period)` Creates a period that encompasses both this period and another one.
`int` `compareTo(Object arg0)`
`int` `compareTo(Period arg0)` Compares the specified period with this period.
`boolean` `equals(Object o)`
`Dur` `getDuration()` Returns the duration of this period.
`DateTime` `getEnd()` Returns the end date of this period.
`DateTime` `getStart()`
`int` `hashCode()`
`boolean` `includes(Date date, boolean inclusive)` Deprecated. use `DateRange.includes(Date, int)` instead.
`boolean` `isEmpty()` An empty period is one that consumes no time.
`void` `setTimeZone(TimeZone timezone)` Updates the start and (possible) end times of this period to reflect the specified timezone status.
`void` `setUtc(boolean utc)` Updates the start and (possible) end times of this period to reflect the specified UTC timezone status.
`PeriodList` `subtract(Period period)` Creates a set of periods resulting from the subtraction of the specified period from this one.
`String` `toString()`

### Methods inherited from class net.fortuna.ical4j.model.DateRange

`adjacent, after, before, contains, getRangeEnd, getRangeStart, includes, includes, intersects`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### Period

    public Period(String aValue)
           throws ParseException

Constructor.

Parameters:
  `aValue` - a string representation of a period
Throws:
  `ParseException` - where the specified string is not a valid representation

#### Period

    public Period(DateTime start,
          DateTime end)

Constructs a new period with the specied start and end date.

Parameters:
  `start` - the start date of the period
  `end` - the end date of the period

#### Period

    public Period(DateTime start,
          Dur duration)

Constructs a new period with the specified start date and duration.

Parameters:
  `start` - the start date of the period
  `duration` - the duration of the period

### Method Detail

#### getDuration

    public final Dur 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

    public final DateTime 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

    public final DateTime getStart()

Returns:
  Returns the start.

#### includes

    public final boolean includes(Date date,
                   boolean inclusive)

Deprecated. use `DateRange.includes(Date, int)` instead.

Parameters:
  `date` - a date to test for inclusion
  `inclusive` - 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

#### add

    public final Period add(Period period)

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

    public final PeriodList subtract(Period period)

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 interest 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

#### setUtc

    public void setUtc(boolean utc)

Updates the start and (possible) end times of this period to reflect the specified UTC timezone status.

Parameters:
  `utc` - indicates whether the period is in UTC time

#### setTimeZone

    public final void setTimeZone(TimeZone timezone)

Updates the start and (possible) end times of this period to reflect the specified timezone status.

Parameters:
  `timezone` - a timezone for the period

#### toString

    public final String toString()

Overrides:
  `toString` in class `Object`

#### compareTo

    public final int compareTo(Object arg0)

Specified by:
  `compareTo` in interface `Comparable`

#### compareTo

    public final int compareTo(Period arg0)

Compares the specified period with this period.

Parameters:
  `arg0` - 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

    public final boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public final int hashCode()

Overrides:
  `hashCode` in class `Object`