com.moneydance.apps.md.model.time
Class TimeIntervalUtil

java.lang.Object
  extended by com.moneydance.apps.md.model.time.TimeIntervalUtil

public class TimeIntervalUtil
extends java.lang.Object

Utilities for managing time intervals for graphs and reports.

Author:
Kevin Menningen - Mennē Software Solutions, LLC

Constructor Summary
TimeIntervalUtil()
           
 
Method Summary
static int getColumnIndex(com.moneydance.apps.md.controller.time.GraphInterval[] dateRanges, int dateInt)
          Given a date, return which column it should belong to in a list of date ranges.
static com.moneydance.apps.md.controller.time.GraphInterval[] getDateIntervalList(CustomDateFormat dateFormat, DateRange dateRange, TimeInterval interval)
          Generate a list of date intervals given a date range and a time interval setting.
 int getIntervalEnd(int date, TimeInterval interval)
          Given a date and a desired interval, return the ending date.
 java.lang.String[] getIntervalLabels(CustomDateFormat fmt, int numIntervals, int startInterval, TimeInterval interval)
          Given a start date, number of intervals, and time interval, return a list of strings, one label for each interval.
 int[] getIntervalPoints(int numIntervals, int startInterval, TimeInterval interval)
          Given a start date, number of intervals, and time interval, return a list of dates, one date per interval.
 int getIntervalStart(int date, TimeInterval interval)
          Given a date and a desired interval, return the starting date.
 int getNumIntervals(int startInterval, int lastInterval, TimeInterval interval)
          Given a start and end date, return the number of intervals needed for a particular time interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeIntervalUtil

public TimeIntervalUtil()
Method Detail

getIntervalPoints

public int[] getIntervalPoints(int numIntervals,
                               int startInterval,
                               TimeInterval interval)
Given a start date, number of intervals, and time interval, return a list of dates, one date per interval.

Parameters:
numIntervals - The number of intervals.
startInterval - The start date (beginning of the first interval).
interval - Length of each interval.
Returns:
An array of dates as integers, one date for each interval.

getIntervalLabels

public java.lang.String[] getIntervalLabels(CustomDateFormat fmt,
                                            int numIntervals,
                                            int startInterval,
                                            TimeInterval interval)
Given a start date, number of intervals, and time interval, return a list of strings, one label for each interval.

Parameters:
fmt - The date format to use for the labels.
numIntervals - The number of intervals.
startInterval - The start date (beginning of the first interval).
interval - Length of each interval.
Returns:
An array of string labels for an interval list, one label for each interval.

getNumIntervals

public int getNumIntervals(int startInterval,
                           int lastInterval,
                           TimeInterval interval)
Given a start and end date, return the number of intervals needed for a particular time interval.

Parameters:
startInterval - The starting date (on an even interval) as an integer.
lastInterval - The ending date (on an even interval) as an integer.
interval - Length of each interval.
Returns:
The number of intervals represented by the date range.

getIntervalStart

public int getIntervalStart(int date,
                            TimeInterval interval)
Given a date and a desired interval, return the starting date. This essentially rounds down to the beginning of the interval that encapsulates the given date.

Parameters:
date - The date.
interval - Length of the interval.
Returns:
The starting date of the interval that encapsulates the given date.

getIntervalEnd

public int getIntervalEnd(int date,
                          TimeInterval interval)
Given a date and a desired interval, return the ending date. This essentially rounds up to the end of the interval that encapsulates the given date.

Parameters:
date - The date.
interval - Length of the interval.
Returns:
The ending date of the interval that encapsulates the given date.

getDateIntervalList

public static com.moneydance.apps.md.controller.time.GraphInterval[] getDateIntervalList(CustomDateFormat dateFormat,
                                                                                         DateRange dateRange,
                                                                                         TimeInterval interval)
Generate a list of date intervals given a date range and a time interval setting.

Parameters:
dateFormat - Display format for dates (passed to GraphInterval).
dateRange - The range of dates to split up into intervals.
interval - The size of each interval.
Returns:
A list of date ranges, each range of size interval, that covers the entire perios specified by dateRange.

getColumnIndex

public static int getColumnIndex(com.moneydance.apps.md.controller.time.GraphInterval[] dateRanges,
                                 int dateInt)
Given a date, return which column it should belong to in a list of date ranges.

Parameters:
dateRanges - The list of date ranges, one range for each column.
dateInt - The date to find the appropriate column for.
Returns:
The index, or -1 if it does not belong to any of the columns.