Class Period<T extends Temporal>

  • 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:
    Serialized Form
    • Constructor Detail

      • Period

        public Period​(T start,
                      T end)
        Constructs a new period with the specified start and end date.
        Parameters:
        start - the start date of the period
        end - the end date of the period
      • Period

        public Period​(T start,
                      T end,
                      CalendarDateFormat dateFormat)
        Constructs a new period with the specified start and end date with a common date format.
        Parameters:
        start - the start date of the period
        end - the end date of the period
        dateFormat - the format used to generate string representations
      • 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​(T 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

      • parse

        public static <T extends TemporalPeriod<T> parse​(String value)
        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

        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 T 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 T getStart()
        Returns:
        Returns the start.
      • includes

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

        public final boolean includes​(Temporal date)
        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

        public final Period<T> add​(Period<T> 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<T> subtract​(Period<T> 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 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

        public String 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.
        Overrides:
        toString in class Object
        Returns:
        a string representation of the period
      • toString

        public String toString​(ZoneId zoneId)
        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

        public boolean intersects​(Period<?> other)
        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

        public org.threeten.extra.Interval toInterval​(ZoneId zoneId)
      • compareTo

        public final int compareTo​(Period<T> period)
        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<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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getComponent

        public Component getComponent()
      • setComponent

        public void setComponent​(Component component)