Class TimeFrame

  • All Implemented Interfaces:
    java.io.Serializable, ITimeFrameSource

    public final class TimeFrame
    extends java.lang.Object
    implements ITimeFrameSource
    Immutable class which represents an interval of time with a beginning and an end. The beginning value is inclusive and the end value is exclusive. In other words, the time frame of 1pm to 2pm includes 1pm, but not 2pm. 1:59:59 is the last value in the TimeFrame.

    TimeFrames can be constructed by calling the valueOf static factory methods valueOf(Time, Time) (yielding a TimeFrame between two absolute times) and valueOf(Time, Duration) yielding a TimeFrame starting at an absolute time and having a given length.

    The start and end of a TimeFrame can be retrieved by calling getStart and getEnd. Its duration can be retrieved by calling getDuration.

    The contains(Time) method can be called to determine if a TimeFrame contains a given point in time. The overlaps(TimeFrame) method can be called to determine if two TimeFrames overlap.

    The eachDay(TimeOfDay, TimeOfDay) will return a TimeFrameSource which generates a TimeFrame using the two times of day. In other words, if the start is 3pm and the end is 4pm, the TimeFrameSource returned will yield 3-4pm on the day it is called (each day).

    Since:
    1.2.6
    Author:
    Jonathan Locke
    See Also:
    Serialized Form
    • Method Detail

      • eachDay

        public static ITimeFrameSource eachDay​(TimeOfDay startTimeOfDay,
                                               TimeOfDay endTimeOfDay)
        Creates an ITimeFrameSource source for start and end TimeOfDays. For example, called with 3pm and 5pm as parameters, the TimeFrame source returned would produce TimeFrame objects representing 3pm-5pm on whatever day it is when the caller calls the TimeFrameSource interface.
        Parameters:
        startTimeOfDay - the start TimeOfDay for this TimeFrame each day
        endTimeOfDay - the end TimeOfDay for this TimeFrame each day
        Returns:
        a TimeFrameSource which will return the specified TimeFrame each day
      • valueOf

        public static TimeFrame valueOf​(Time start,
                                        Duration duration)
        Creates a TimeFrame for a start Time and Duration.
        Parameters:
        start - the start Time
        duration - the Duration
        Returns:
        the TimeFrame
        Throws:
        java.lang.IllegalArgumentException - thrown if start Time value is before end Time value
      • valueOf

        public static TimeFrame valueOf​(Time start,
                                        Time end)
        Creates a TimeFrame for given start and end Times.
        Parameters:
        start - the start Time
        end - the end Time
        Returns:
        the TimeFrame
        Throws:
        java.lang.IllegalArgumentException - thrown if start Time value is before end Time value
      • contains

        public boolean contains​(Time time)
        Determines if this TimeFrame contains a given point in time.
        Parameters:
        time - the Time to check
        Returns:
        true if this TimeFrame contains the given time
      • getDuration

        public Duration getDuration()
        Retrieves the Duration of this TimeFrame.
        Returns:
        the Duration of this TimeFrame
      • getEnd

        public Time getEnd()
        Retrieves the end Time of this TimeFrame.
        Returns:
        the end of this TimeFrame
      • getStart

        public Time getStart()
        Retrieves the start Time of this TimeFrame.
        Returns:
        the start of this TimeFrame
      • getTimeFrame

        public TimeFrame getTimeFrame()
        Implementation of ITimeFrameSource that simply returns this TimeFrame.
        Specified by:
        getTimeFrame in interface ITimeFrameSource
        Returns:
        this TimeFrame
      • overlaps

        public boolean overlaps​(TimeFrame timeframe)
        Determines if two TimeFrames overlap.
        Parameters:
        timeframe - the TimeFrame to test
        Returns:
        true if the given TimeFrame overlaps this one
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Converts this TimeFrame to a String representation.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of this object