Class Period

  • All Implemented Interfaces:
    Serializable, Comparable<Period>

    public class Period
    extends DateRange
    implements Comparable<Period>
    $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.
    See Also:
    Serialized Form
    • 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

        @Deprecated
        public Period​(DateTime start,
                      Dur duration)
        Deprecated.
        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
      • Period

        public Period​(DateTime start,
                      TemporalAmount 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 TemporalAmount 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

        @Deprecated
        public final boolean includes​(Date date,
                                      boolean inclusive)
        Deprecated.
        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
      • compareTo

        public final int compareTo​(Period arg0)
        Compares the specified period with this period. First, compare the start dates. If they are the same, compare the end dates.
        Specified by:
        compareTo in interface Comparable<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
      • getComponent

        public Component getComponent()
      • setComponent

        public void setComponent​(Component component)