org.knowceans.util
Class TimeIntervals

java.lang.Object
  extended by org.knowceans.util.TimeIntervals

public class TimeIntervals
extends java.lang.Object

TimeIntervals provides methods to find the time intervals (week, month, year) surrounding a given date. Intervals are expressed as 2-arrays of Date object, corresponding to the start and end times. By convention, intervals include their bounds.

FIXME: daylight saving time shift can create gaps in week and month intervals

Author:
gregor

Constructor Summary
TimeIntervals()
           
 
Method Summary
static java.util.Date[] awayExactDay(java.util.Date d, int whatAway, int howManyAway)
          returns the start and end times of the field (Calendar.*) before / after the start of the day surrounding the date d, rounding the day.
static java.util.Date[] awayExactDay(java.util.Date d, int whatAway, int howManyAway, int howManyLong)
          returns the start and end times of the field (Calendar.*) before / after the start of the day surrounding the date d.
static java.util.Date[] dayOf(java.util.Date d)
          returns the start and end times of the day surrounding the date d.
static java.util.Date[] daysAway(java.util.Date d, int away)
          returns the start and end times of the day before / after the day given in date d.
static boolean isIn(java.util.Date time, java.util.Date[] interval)
          check whether time is within the interval.
static java.util.Date[] join(java.util.Date[] before, java.util.Date[] after)
          joins the limits of the two intervals by taking the start of before and the end of after.
static void main(java.lang.String[] args)
           
static java.util.Date[] monthOf(java.util.Date d)
          returns the start and end times of the month surrounding the date d.
static java.util.Date[] monthsAway(java.util.Date d, int away)
          returns the start and end times of the months before / after the start of the month surrounding the date d.
static java.util.Date[] weekOf(java.util.Date d)
          returns the start and end times of the week surrounding the date d.
static java.util.Date[] weeksAway(java.util.Date d, int away)
          returns the start and end times of the week before / after the start of the week surrounding the date d.
static java.util.Date[] yearOf(java.util.Date d)
          returns the start and end times of the year surrounding the date d.
static java.util.Date[] yearsAway(java.util.Date d, int away)
          returns the start and end times of the years before / after the start of the year surrounding the date d.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeIntervals

public TimeIntervals()
Method Detail

main

public static void main(java.lang.String[] args)

dayOf

public static java.util.Date[] dayOf(java.util.Date d)
returns the start and end times of the day surrounding the date d.

Parameters:
d -
Returns:

weekOf

public static java.util.Date[] weekOf(java.util.Date d)
returns the start and end times of the week surrounding the date d.

Parameters:
d -
Returns:

monthOf

public static java.util.Date[] monthOf(java.util.Date d)
returns the start and end times of the month surrounding the date d.

Parameters:
d -
Returns:

yearOf

public static java.util.Date[] yearOf(java.util.Date d)
returns the start and end times of the year surrounding the date d.

Parameters:
d -
Returns:

daysAway

public static java.util.Date[] daysAway(java.util.Date d,
                                        int away)
returns the start and end times of the day before / after the day given in date d.

Parameters:
d -
away -
Returns:

weeksAway

public static java.util.Date[] weeksAway(java.util.Date d,
                                         int away)
returns the start and end times of the week before / after the start of the week surrounding the date d.

Parameters:
d -
away -
Returns:

monthsAway

public static java.util.Date[] monthsAway(java.util.Date d,
                                          int away)
returns the start and end times of the months before / after the start of the month surrounding the date d.

Parameters:
d -
away -
Returns:

yearsAway

public static java.util.Date[] yearsAway(java.util.Date d,
                                         int away)
returns the start and end times of the years before / after the start of the year surrounding the date d.

Parameters:
d -
away -
Returns:

awayExactDay

public static java.util.Date[] awayExactDay(java.util.Date d,
                                            int whatAway,
                                            int howManyAway,
                                            int howManyLong)
returns the start and end times of the field (Calendar.*) before / after the start of the day surrounding the date d.

Parameters:
d - the date to start from
whatAway - what time measure away (week, day, etc.)
howManyAway - how many of the time measure away
howManyLong - how many time measures as interval
Returns:

awayExactDay

public static java.util.Date[] awayExactDay(java.util.Date d,
                                            int whatAway,
                                            int howManyAway)
returns the start and end times of the field (Calendar.*) before / after the start of the day surrounding the date d, rounding the day. E.g., awayExactDay(now, Calendar.WEEK_OF_YEAR, 8, 8) returns an 8 weeks interval from today 8 weeks ago to yesterday.

Parameters:
d - the date to start from
whatAway - what time measure away (week, day, etc.)
howManyAway - how many of the time measure away
Returns:

isIn

public static boolean isIn(java.util.Date time,
                           java.util.Date[] interval)
check whether time is within the interval.

Parameters:
time -
interval -
Returns:

join

public static java.util.Date[] join(java.util.Date[] before,
                                    java.util.Date[] after)
joins the limits of the two intervals by taking the start of before and the end of after.

Parameters:
before -
after -
Returns: