wicket.util.time
Class TimeFrame

java.lang.Object
  extended by wicket.util.time.TimeFrame
All Implemented Interfaces:
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).

Author:
Jonathan Locke

Method Summary
 boolean contains(Time time)
           
static ITimeFrameSource eachDay(TimeOfDay startTimeOfDay, TimeOfDay endTimeOfDay)
          Returns a timeframe source for a start and end time-of-day.
 Duration getDuration()
           
 Time getEnd()
           
 Time getStart()
           
 TimeFrame getTimeFrame()
          Implementation of ITimeFrameSource that simply returns this timeframe
 boolean overlaps(TimeFrame timeframe)
           
 java.lang.String toString()
           
static TimeFrame valueOf(Time start, Duration duration)
          Creates a time frame for a start and duration
static TimeFrame valueOf(Time start, Time end)
          Creates a time frame for a start and end time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

eachDay

public static ITimeFrameSource eachDay(TimeOfDay startTimeOfDay,
                                       TimeOfDay endTimeOfDay)
Returns a timeframe source for a start and end time-of-day. 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 time for this time frame each day
endTimeOfDay - The end time for this time frame each day
Returns:
A timeframe source which will return the specified timeframe each day

valueOf

public static TimeFrame valueOf(Time start,
                                Duration duration)
Creates a time frame for a start and duration

Parameters:
start - The start time
duration - The duration
Returns:
The time frame
Throws:
java.lang.IllegalArgumentException - Thrown if start time is before end time

valueOf

public static TimeFrame valueOf(Time start,
                                Time end)
Creates a time frame for a start and end time

Parameters:
start - The start time
end - The end time
Returns:
The time frame
Throws:
java.lang.IllegalArgumentException - Thrown if start time is before end time

contains

public boolean contains(Time time)
Parameters:
time - The time to check
Returns:
True if this time frame contains the given time

getDuration

public Duration getDuration()
Returns:
The duration of this time frame

getEnd

public Time getEnd()
Returns:
The end of this time frame

getStart

public Time getStart()
Returns:
The start of this time frame

getTimeFrame

public TimeFrame getTimeFrame()
Implementation of ITimeFrameSource that simply returns this timeframe

Specified by:
getTimeFrame in interface ITimeFrameSource
Returns:
Gets this timeframe

overlaps

public boolean overlaps(TimeFrame timeframe)
Parameters:
timeframe - The timeframe to test
Returns:
True if the given timeframe overlaps this one

toString

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


Copyright © 2004-2007 Wicket developers. All Rights Reserved.