com.miginfocom.util.dates
Class ImmutableDateRange

java.lang.Object
  extended by com.miginfocom.util.dates.ImmutableDateRange
All Implemented Interfaces:
DateRangeI, TimeSpan, java.io.Serializable, java.lang.Comparable

public final class ImmutableDateRange
extends java.lang.Object
implements DateRangeI

An immutable DateRange. Objects of this class will be truly immutable.

Uses a private DateRange and transfers all methods to that object.

See Also:
DateRangeI, DateRange, MutableDateRange, Serialized Form

Field Summary
 
Fields inherited from interface com.miginfocom.util.dates.DateRangeI
CUSTOM_NVP, DATE_RANGE_NAMES, DATE_RANGES, DATE_RANGES_CUSTOM, DATE_RANGES_FROM_DAY, DAY_NVP, HOUR_NVP, MINUTE_NVP, MONTH_NVP, RANGE_TYPE_CUSTOM, RANGE_TYPE_DAY, RANGE_TYPE_HOUR, RANGE_TYPE_MINUTE, RANGE_TYPE_MONTH, RANGE_TYPE_OFFSET, RANGE_TYPE_SECOND, RANGE_TYPE_WEEK, RANGE_TYPE_YEAR_MONTHS, RANGE_TYPE_YEAR_WEEKS, RANGE_TYPES_MILLIS, SECOND_NVP, WEEK_NVP, YEAR_MONTHS_NVP, YEAR_WEEKS_NVP
 
Constructor Summary
ImmutableDateRange()
          Constructor for current date/time.
ImmutableDateRange(java.util.Date start, java.util.Date end, boolean endIsExcluding, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructor.
ImmutableDateRange(DateRangeI dateRange)
          Constructs a range that has the same range as dateRange.
ImmutableDateRange(DateRangeI dateRange, boolean hasDate, boolean hasTime)
          Constructs a range that has the same range as dateRange.
ImmutableDateRange(DateRangeI dateRange1, DateRangeI dateRange2)
          Sets the date range to the maximum date span possible with the two ranges start and end dates.
ImmutableDateRange(DateRangeI dateRange, int boundaryType)
          Constructs a range that has the same range as dateRange and then rounds it to boundsryType.
ImmutableDateRange(long date, int boundaryType, int size, AtRefRangeNumber align, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range and set it to a boundary to the first and last millisecond of a boundary.
ImmutableDateRange(long date, int boundaryType, int size, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range and set it to a boundary to the first and last millisecond of a boundary.
ImmutableDateRange(long start, long end, boolean endExcluding, int boundaryType, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range and set it to a boundary to the first and last millisecond of a boundary.
ImmutableDateRange(long start, long end, boolean endIsExcluding, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructor.
ImmutableDateRange(long start, long end, boolean endIsExcluding, java.util.TimeZone timeZone, java.util.Locale locale, boolean hasDate, boolean hasTime)
          Constructor.
ImmutableDateRange(long date, java.util.TimeZone timeZone, java.util.Locale locale)
          Constructs a range that simulates a singe point in time.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares startdates, and if they are the same, end dates.
 ImmutableDateRange createIntersection(DateRangeI dateRange)
          Returns an ImmutableDateRange with intersecting (overlaping) date range.
 boolean equals(java.lang.Object o)
          Returns true if obj is != null, is an instance of DateRangeI and represents date range with the same start and end millisecond
 MutableDateRange getDateRangeClone()
          Returns the date range that the object spans as a clone which is safe to change without chaning the original time span.
 DateRangeI getDateRangeForReading()
          Returns the date range that the object spans.
 java.lang.String getDurationString(java.lang.String formatString)
          Calls DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for the start and end dates and returns the result.
 java.util.Calendar getEnd()
          This is simply short for: getEnd(false), which means it will typically have milliseconds set to 999.
 java.util.Calendar getEnd(boolean excluding)
          Returns the actual contained Calendar.
 int getEndField(int field)
          This is simply short for: getEndField(field, false), which means it will typically have milliseconds set to 999.
 int getEndField(int field, boolean excluding)
          Forwarded to Calendar#get.
 ImmutableDateRange getEndInstant()
          This is simply short for: getEndInstant(false), which means it will typically have milliseconds set to 999.
 ImmutableDateRange getEndInstant(boolean excluding)
          Returns an ImmutableDateRange representing the end of this date range.
 long getEndMillis()
          This is simply short for: getEndMillis(false), which means it will typically have milliseconds set to 999.
 long getEndMillis(boolean excluding)
          Returns the end date in milliseconds.
 java.util.Date getEndTime()
          This is simply short for: getEndTime(false), which means it will typically have milliseconds set to 999.
 java.util.Date getEndTime(boolean excluding)
          Returns a new Date object representing the end time
 boolean getHasDate()
          A simple settable property that does nothing for the contained values or calculations.
 boolean getHasTime()
          A simple settable property that does nothing for the contained values or calculations.
 ImmutableDateRange getImmutable()
          Returns the range as a true immutable date range.
 java.util.Locale getLocale()
          Returns the locale associated with this time zone or null if the default should be used.
 java.util.Calendar getMiddle()
          Calulates the time in the middle of 'startDate' and 'endDate'.
 long getMiddleMillis()
          Calulates the time in the middle of 'startDate' and 'endDate'.
 long getMillisSpanned(boolean dSTSafe, boolean excluding)
          Returns the number of milliseconds this range spans.
 int getRangeType()
          Returns the type of range that this DataSpan spans.
 java.util.Calendar getRelative(double perc)
          Returns a date that are perc percent into the range.
 long getRelativeMillis(double perc)
          Returns a date that are perc percent into the range.
 DateRangeI getRelativeRange(double startPerc, double endPerc)
          Returns a date range that start from startPerc percent into the range until endPerc into the range.
 int getSize(int rangeType, boolean dSTSafe)
          Returns the number of seconds, minutes, hours, days, weeks, months or years betwen start and end date, inclusive.
 java.util.Calendar getStart()
          Returns a clone of the start date, free to change and it wont affect the range.
 int getStartField(int field)
          Forwarded to Calendar#get.
 ImmutableDateRange getStartInstant()
          Returns an ImmutableDateRange representing the start of this date range.
 long getStartMillis()
          Returns the start date in milliseconds.
 java.util.Date getStartTime()
          Returns a new Date object representing the start time
 java.util.ArrayList getSubDateList(int field, int[] values, int occurField, int[] dayOfWeekOccur, int maxCount, boolean asRanges)
          Runs an iterator over the range with sizes field and returns all date/times that's inside this range and which have a field value that is one of the integers in values.
 java.util.TimeZone getTimeZone()
          Returns the time zone associated with this time zone or null if the default should be used.
 MutableDateRange getWritableDateRange()
          Returns the contained date range for editing.
 int hashCode()
           
 boolean isContaining(DateRangeI innerRange)
          Checks if a 'innerDateSpan' is compleately inside or equal to this range.
 boolean isContaining(long timeInMillis, boolean disregardSorting)
          Returns if the millisecond is within the range, inclusive.
 boolean isContinuous(DateRangeI range)
          Checks if dateRange overlaps (or touches) this date range or if they are next to eachother so that there are no time between them and they thus form a continuous date range.
 boolean isInSame(int rangeType)
          Returns if cal1 and cal2 is in the same range type.
 boolean isOverlapping(DateRangeI range)
          Checks if dateRange overlaps (or touches) this date range.
 boolean isOverlapping(DateRangeI range, DateRangeI withinRangeI)
          Checks if dateRange overlaps (or touches) this date range.
 boolean isSorted()
          Returns if startDate is before (or same) as endDate (to the millisecond)
 boolean isSpanningTime()
          Returns if start date is not same as end date.
 java.util.Iterator iterator(int boundaryType)
          Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next().
 java.util.Iterator iterator(int boundaryType, int amount)
          Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next().
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String formatString, boolean endIsExcluding, boolean includeOffset)
          Retuns a string representation of the date range.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ImmutableDateRange

public ImmutableDateRange()
Constructor for current date/time.


ImmutableDateRange

public ImmutableDateRange(long start,
                          long end,
                          boolean endIsExcluding,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
Constructor.

Parameters:
start - The start date/time in milliseconds.
end - The end date/time in milliseconds.
endIsExcluding - Set to true if the end date is 'excluding', normally meaning that the milliseconds are are an even number (0).
timeZone - The time zone or null for default.
locale - The locale or null for default.

ImmutableDateRange

public ImmutableDateRange(long start,
                          long end,
                          boolean endIsExcluding,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale,
                          boolean hasDate,
                          boolean hasTime)
Constructor.

Parameters:
start - The start date/time in milliseconds.
end - The end date/time in milliseconds.
endIsExcluding - Set to true if the end date is 'excluding', normally meaning that the milliseconds are are an even number (0).
timeZone - The time zone or null for default.
locale - The locale or null for default.
hasDate - If the date in this date range is relevant. Only as inpormation, doesn't affect calculations.
hasTime - If the time in this date range is relevant. Only as inpormation, doesn't affect calculations.

ImmutableDateRange

public ImmutableDateRange(java.util.Date start,
                          java.util.Date end,
                          boolean endIsExcluding,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
Constructor.

Parameters:
start - The start date/time
end - The end date/time. Can be same object as start to simulate a single point in time.
endIsExcluding - Set to true if the end date is 'excluding', normally meaning that the milliseconds are are an even number (0).
timeZone - The time zone or null for default.
locale - The locale or null for default.

ImmutableDateRange

public ImmutableDateRange(long date,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
Constructs a range that simulates a singe point in time. It actually spans 1 millisecond since both start and end date are considered inclusive.
Same as new DateRange(date, date, false);

Parameters:
date - The start and end date. Object is cloned. Not null.

ImmutableDateRange

public ImmutableDateRange(DateRangeI dateRange)
Constructs a range that has the same range as dateRange. Makes a defensive copy of the sent in date range. The new range will have the same immutable state.

Parameters:
dateRange - The AtStart and end date. Object is cloned for storing. Not null

ImmutableDateRange

public ImmutableDateRange(DateRangeI dateRange,
                          int boundaryType)
Constructs a range that has the same range as dateRange and then rounds it to boundsryType. Makes a defensive copy of the sent in date range.

Parameters:
dateRange - The AtStart and end date. Object is cloned for storing. Not null
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. It can be one of: RANGE_TYPE_SECOND Set the dates to seconds's boundaries
RANGE_TYPE_MINUTE Set the dates to minutes's boundaries
RANGE_TYPE_HOUR Set the dates to hous's boundaries
RANGE_TYPE_DAY Set the dates to day's boundaries
RANGE_TYPE_WEEK Set the dates to a week's boundaries
RANGE_TYPE_MONTH Set the dates to a month's boundaries
RANGE_TYPE_YEAR_MONTHS Set the dates to a year's boundaries. Jan 1 to Dec 31.
RANGE_TYPE_YEAR_WEEKS Set the dates to a year's boundaries. Week 01 to week 52/53

ImmutableDateRange

public ImmutableDateRange(DateRangeI dateRange,
                          boolean hasDate,
                          boolean hasTime)
Constructs a range that has the same range as dateRange. Makes a defensive copy of the sent in date range. The new range will have the same immutable state.

Parameters:
dateRange - The AtStart and end date. Object is cloned for storing. Not null
hasDate - If the date range is considered to contain the date
hasTime - If the date range is considered to contain the time-of-day
See Also:
getHasDate(), getHasTime()

ImmutableDateRange

public ImmutableDateRange(long start,
                          long end,
                          boolean endExcluding,
                          int boundaryType,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
Constructs a range and set it to a boundary to the first and last millisecond of a boundary.

Parameters:
start - Start date in milliseconds.
end - End date in milliseconds.
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. It can be one of: RANGE_TYPE_SECOND Set the dates to seconds's boundaries
RANGE_TYPE_MINUTE Set the dates to minutes's boundaries
RANGE_TYPE_HOUR Set the dates to hous's boundaries
RANGE_TYPE_DAY Set the dates to day's boundaries
RANGE_TYPE_WEEK Set the dates to a week's boundaries
RANGE_TYPE_MONTH Set the dates to a month's boundaries
RANGE_TYPE_YEAR_MONTHS Set the dates to a year's boundaries. Jan 1 to Dec 31.
RANGE_TYPE_YEAR_WEEKS Set the dates to a yearäs boundaries. Week 01 to week 52/53
endExcluding - Set to true if the end date's last millisecond is 'excluded' from the range, normally meaning that the milliseconds are are an even number (000).

ImmutableDateRange

public ImmutableDateRange(long date,
                          int boundaryType,
                          int size,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
Constructs a range and set it to a boundary to the first and last millisecond of a boundary.

Parameters:
date - The startDate that will be set to the given boundary. endDate will be cloned from this object and set to the given boundary. Object is cloned for storing. Not null
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. It can be one of: RANGE_TYPE_SECOND Set the dates to seconds's boundaries
RANGE_TYPE_MINUTE Set the dates to minutes's boundaries
RANGE_TYPE_HOUR Set the dates to hous's boundaries
RANGE_TYPE_DAY Set the dates to day's boundaries
RANGE_TYPE_WEEK Set the dates to a week's boundaries
RANGE_TYPE_MONTH Set the dates to a month's boundaries
RANGE_TYPE_YEAR_MONTHS Set the dates to a year's boundaries. Jan 1 to Dec 31.
RANGE_TYPE_YEAR_WEEKS Set the dates to a year's boundaries. Week 01 to week 52/53
size - The number of boundaryType to span. Must be > 0.

ImmutableDateRange

public ImmutableDateRange(long date,
                          int boundaryType,
                          int size,
                          AtRefRangeNumber align,
                          java.util.TimeZone timeZone,
                          java.util.Locale locale)
Constructs a range and set it to a boundary to the first and last millisecond of a boundary.

Parameters:
date - The date in milliseconds that will be set to the given boundary.
boundaryType - Both dates will be changed to the start/end boundary indicated by 'boundaryType'. It can be one of: RANGE_TYPE_SECOND Set the dates to seconds's boundaries
RANGE_TYPE_MINUTE Set the dates to minutes's boundaries
RANGE_TYPE_HOUR Set the dates to hous's boundaries
RANGE_TYPE_DAY Set the dates to day's boundaries
RANGE_TYPE_WEEK Set the dates to a week's boundaries
RANGE_TYPE_MONTH Set the dates to a month's boundaries
RANGE_TYPE_YEAR_MONTHS Set the dates to a year's boundaries. Jan 1 to Dec 31.
RANGE_TYPE_YEAR_WEEKS Set the dates to a year's boundaries. Week 01 to week 52/53
size - The number of boundaryType to span. Must be > 0.
align - Specifies how to align the new time range relative to the old one. If null the alignment will be centered.

The most usable types are probably:

  • AtStart Align it so that the start will be the specified amount of boundaryType from the old start. For instance two weeks, if boundaryType is DateRangeI.RANGE_TYPE_WEEK and the argument is new AtStart(2f).
  • AtEnd Align it so that the end will be the specified amount of boundaryType from the old end. Most logically a negative value will be used. E.g. new AtEnd(-1f).
  • AtFraction 0f will align starts, 0.5f will center and 1f will align ends. All values in between is also valid of course.
See Also:
MutableDateRange.setSize(int, int, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber)

ImmutableDateRange

public ImmutableDateRange(DateRangeI dateRange1,
                          DateRangeI dateRange2)
Sets the date range to the maximum date span possible with the two ranges start and end dates. They don't have to be sorted.
One of the ranges can be null but not both.
Time Zone/Locale will be taken from dateRange1 if not null in which case it will be taken from dateRange2.

Parameters:
dateRange1 - Date range 1.
dateRange2 - Date range 2.
Method Detail

createIntersection

public final ImmutableDateRange createIntersection(DateRangeI dateRange)
Returns an ImmutableDateRange with intersecting (overlaping) date range.

Parameters:
dateRange - The date range to intersect with. Not null and must be sorted.
Returns:
An intersecting ImmutableDateRange or null if they don't overlap.
See Also:
isSorted()

getTimeZone

public java.util.TimeZone getTimeZone()
Description copied from interface: DateRangeI
Returns the time zone associated with this time zone or null if the default should be used.

Specified by:
getTimeZone in interface DateRangeI
Returns:
The time zone associated with this time zone or null if the default should be used.

getLocale

public java.util.Locale getLocale()
Description copied from interface: DateRangeI
Returns the locale associated with this time zone or null if the default should be used.

Specified by:
getLocale in interface DateRangeI
Returns:
The locale associated with this time zone or null if the default should be used.

getHasDate

public final boolean getHasDate()
Description copied from interface: DateRangeI
A simple settable property that does nothing for the contained values or calculations. It is just a "tag"-boolean that can be interpreted by users of this class.

Specified by:
getHasDate in interface DateRangeI
Returns:
If the range's date should be considered. Default is true.

getHasTime

public final boolean getHasTime()
Description copied from interface: DateRangeI
A simple settable property that does nothing for the contained values or calculations. It is just a "tag"-boolean that can be interpreted by users of this class.

Specified by:
getHasTime in interface DateRangeI
Returns:
If the range's date should be considered. Default is true.

getDateRangeClone

public final MutableDateRange getDateRangeClone()
Description copied from interface: TimeSpan
Returns the date range that the object spans as a clone which is safe to change without chaning the original time span. If the range is only to be read from use TimeSpan.getDateRangeForReading() instead to avoid unnecessary object cloning.

Specified by:
getDateRangeClone in interface TimeSpan
Returns:
Returns the date range that the object spans.

getDateRangeForReading

public final DateRangeI getDateRangeForReading()
Description copied from interface: TimeSpan
Returns the date range that the object spans. If the object contains an immutable date range or a range that must not be changed that is returned here. In order to get a truly immutable date range that will not change call DateRangeI.getImmutable() on the returned range. The contract is to not change the returned date range.

Specified by:
getDateRangeForReading in interface TimeSpan
Returns:
Returns the date range that the object spans.

getWritableDateRange

public final MutableDateRange getWritableDateRange()
Description copied from interface: TimeSpan
Returns the contained date range for editing. If the local date range isn't allowed to be edited an UnsupportedOperationException should be thrown.

Specified by:
getWritableDateRange in interface TimeSpan
Returns:
The contained date range for editing.

getImmutable

public final ImmutableDateRange getImmutable()
Description copied from interface: DateRangeI
Returns the range as a true immutable date range.

Specified by:
getImmutable in interface DateRangeI
Returns:
The range as a true immutable date range.

getEnd

public final java.util.Calendar getEnd(boolean excluding)
Description copied from interface: DateRangeI
Returns the actual contained Calendar. Should absolutely not be changed, though this is not checked. Nasty buggs could be the result of changing this retirned com.miginfocom.calendar.

Specified by:
getEnd in interface DateRangeI
Parameters:
excluding - If true the returned date will have one millisecond added first. Depending on how the returned com.miginfocom.calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
A cloned com.miginfocom.calendar representing the end date.

getEnd

public java.util.Calendar getEnd()
Description copied from interface: DateRangeI
This is simply short for: getEnd(false), which means it will typically have milliseconds set to 999.

Specified by:
getEnd in interface DateRangeI
See Also:
DateRangeI.getEnd(boolean)

getEndTime

public final java.util.Date getEndTime(boolean excluding)
Description copied from interface: DateRangeI
Returns a new Date object representing the end time

Specified by:
getEndTime in interface DateRangeI
Parameters:
excluding - If true the returned date will have one millisecond added first. Depending on how the returned com.miginfocom.calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
A new Date object representing the end time

getEndTime

public java.util.Date getEndTime()
Description copied from interface: DateRangeI
This is simply short for: getEndTime(false), which means it will typically have milliseconds set to 999.

Specified by:
getEndTime in interface DateRangeI
See Also:
DateRangeI.getEndTime(boolean)

getEndField

public final int getEndField(int field,
                             boolean excluding)
Description copied from interface: DateRangeI
Forwarded to Calendar#get.

Specified by:
getEndField in interface DateRangeI
Parameters:
field - The field to get
excluding - If true the returned date/time will be for the "next" millisecond that end date denotes. That date actually does not belong to this range but it is common for that value to be used for example when displaying a time range (e.g. 10:00:00.000 -> 11:15:00.000).
Returns:
The field's value
See Also:
Calendar.get(int)

getEndField

public int getEndField(int field)
Description copied from interface: DateRangeI
This is simply short for: getEndField(field, false), which means it will typically have milliseconds set to 999.

Specified by:
getEndField in interface DateRangeI
See Also:
DateRangeI.getEndField(int, boolean)

getEndMillis

public final long getEndMillis(boolean excluding)
Description copied from interface: DateRangeI
Returns the end date in milliseconds. Especially useful when dealing with immutable date ranges since no defensive cloning is needed compared to DateRangeI.getEnd(boolean)

Specified by:
getEndMillis in interface DateRangeI
Parameters:
excluding - If true the returned date will have one millisecond added first. Depending on how the returned com.miginfocom.calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
The end date in milliseconds

getEndMillis

public final long getEndMillis()
Description copied from interface: DateRangeI
This is simply short for: getEndMillis(false), which means it will typically have milliseconds set to 999.

Specified by:
getEndMillis in interface DateRangeI
See Also:
DateRangeI.getEndMillis(boolean)

getStartInstant

public ImmutableDateRange getStartInstant()
Description copied from interface: DateRangeI
Returns an ImmutableDateRange representing the start of this date range.

Specified by:
getStartInstant in interface DateRangeI
Returns:
An ImmutableDateRange representing the start of this date range.

getEndInstant

public ImmutableDateRange getEndInstant(boolean excluding)
Description copied from interface: DateRangeI
Returns an ImmutableDateRange representing the end of this date range.

Specified by:
getEndInstant in interface DateRangeI
Parameters:
excluding - If true the returned date range will have one millisecond added first. Depending on how the returned calendar should be used this might, or might not, be desirable. For example, if the range spans exactly four days and the returned date should be used for displaying in what day it ends, then you should set this argument to false. But if it should be used to show a time range, for instance 09:00 to 10:00 the argument should be true since he actual stored end date/time is 09:59:999 (inclusive). See class info.
Returns:
An ImmutableDateRange representing the end of this date range.

getEndInstant

public ImmutableDateRange getEndInstant()
Description copied from interface: DateRangeI
This is simply short for: getEndInstant(false), which means it will typically have milliseconds set to 999.

Specified by:
getEndInstant in interface DateRangeI
See Also:
DateRangeI.getEndInstant(boolean)

getStart

public final java.util.Calendar getStart()
Description copied from interface: DateRangeI
Returns a clone of the start date, free to change and it wont affect the range.

Specified by:
getStart in interface DateRangeI
Returns:
A clone of the start date

getStartTime

public final java.util.Date getStartTime()
Description copied from interface: DateRangeI
Returns a new Date object representing the start time

Specified by:
getStartTime in interface DateRangeI
Returns:
A new Date object representing the start time

getStartField

public final int getStartField(int field)
Description copied from interface: DateRangeI
Forwarded to Calendar#get.

Specified by:
getStartField in interface DateRangeI
Parameters:
field - The field to get. E.g. Calendar.WEEK.
Returns:
The field's value
See Also:
Calendar.get(int)

getStartMillis

public final long getStartMillis()
Description copied from interface: DateRangeI
Returns the start date in milliseconds. Especially useful when dealing with immutable date ranges since no defensive cloning is needed compared to DateRangeI.getStart()

Specified by:
getStartMillis in interface DateRangeI
Returns:
The start date in milliseconds

isSpanningTime

public final boolean isSpanningTime()
Description copied from interface: DateRangeI
Returns if start date is not same as end date. Even if they are the same it actually spans 1 millisecond since both start and end date are considered inclusive.
Notice that DateRangeI.getMillisSpanned(boolean, boolean) will return 1.

Specified by:
isSpanningTime in interface DateRangeI
Returns:
If start date is not same as end date.

isSorted

public final boolean isSorted()
Description copied from interface: DateRangeI
Returns if startDate is before (or same) as endDate (to the millisecond)

Specified by:
isSorted in interface DateRangeI
Returns:
If startDate is before (or same) as endDate (to the millisecond)

isInSame

public final boolean isInSame(int rangeType)
Description copied from interface: DateRangeI
Returns if cal1 and cal2 is in the same range type. (e.g. DateRangeI.RANGE_TYPE_DAY) Much faster than getSpanCount(rangeType, xxx) == 0 !

Specified by:
isInSame in interface DateRangeI
Parameters:
rangeType - The range type. DateRangeI.RANGE_TYPE_xxx. Not RANGE_TYPE_CUSTOM.
Returns:
If cal1 and cal2 is in the same range type.d

getSize

public final int getSize(int rangeType,
                         boolean dSTSafe)
Description copied from interface: DateRangeI
Returns the number of seconds, minutes, hours, days, weeks, months or years betwen start and end date, inclusive. For instance 2002-12-31 to 2003-01-01 spans two years!
RANGE_TYPE_MONTH, RANGE_TYPE_YEAR_MONTHS and RANGE_TYPE_YEAR_WEEKS are passed in to getSpanCountIter(...) since their length is variable and has to be iterated anyway.

Specified by:
getSize in interface DateRangeI
Parameters:
rangeType - One of: DateRangeI.RANGE_TYPE_SECOND Counts the seconds
DateRangeI.RANGE_TYPE_MINUTE Counts the minutes
DateRangeI.RANGE_TYPE_HOUR Counts the hours
DateRangeI.RANGE_TYPE_DAY Counts the days
DateRangeI.RANGE_TYPE_WEEK Counts the weeks
DateRangeI.RANGE_TYPE_MONTH Counts the months (iterative algorithm)
DateRangeI.RANGE_TYPE_YEAR_MONTHS Counts the years, month based. jan 1 to dec 31 (iterative algorithm)
DateRangeI.RANGE_TYPE_YEAR_WEEKS Counts the years, week based. week 01 to week 52/53 (iterative algorithm)
NOTE! Getting the time zone is currently a quite expensive call. So only set this to true if it is really needed.
dSTSafe - For instance a day can span 23, 24 or 25 hours depending on if it's the Daylight saving day. With this set to true the returned value will be compensated to return 24 for all days. This is also valid for minutes and seconds. Note that if true adding the returned amount to start may not end up on end but on one earlier or later.
Returns:
The number of days, weeks, months or years betwen two dates inclusive, which means never 0.

getMillisSpanned

public final long getMillisSpanned(boolean dSTSafe,
                                   boolean excluding)
Description copied from interface: DateRangeI
Returns the number of milliseconds this range spans.

Specified by:
getMillisSpanned in interface DateRangeI
Parameters:
dSTSafe - If true transitions over a DST border will be compensated for the offset. false is just a endDate.getTimeInMillis() - startDate.getTimeInMillis() + 1. false is as UTC-mode.
excluding - If true the returned value will have one millisecond added first. Depending on how the returned value should be used this might, or might not, be desirable.
Basically setting to true will return 1000 millis for one spanned second and setting to false will return 999 which is the internal representation.
Returns:
The number of milliseconds from start to end date. Always > 0. (E.g. 1000 for one second)
See Also:
DateRangeI.getEnd(boolean), DateRangeI.isSpanningTime()

isOverlapping

public final boolean isOverlapping(DateRangeI range)
Description copied from interface: DateRangeI
Checks if dateRange overlaps (or touches) this date range. Inclusive.

Specified by:
isOverlapping in interface DateRangeI
Parameters:
range - The date range to check if this is overlapping with
Returns:
If dateRange overlaps (or touches) this date range. Inclusive.

isContinuous

public final boolean isContinuous(DateRangeI range)
Description copied from interface: DateRangeI
Checks if dateRange overlaps (or touches) this date range or if they are next to eachother so that there are no time between them and they thus form a continuous date range.

Specified by:
isContinuous in interface DateRangeI
Parameters:
range - The date range to check if this is continuous with
Returns:
If dateRange overlaps or is next to this date range.

isOverlapping

public final boolean isOverlapping(DateRangeI range,
                                   DateRangeI withinRangeI)
Description copied from interface: DateRangeI
Checks if dateRange overlaps (or touches) this date range. Inclusive.

Specified by:
isOverlapping in interface DateRangeI
Parameters:
range - The date range to check if this is overlapping with
withinRangeI - Only return true if there is an overlap within this range. Not null.
Returns:
If dateRange overlaps (or touches) this date range. Inclusive.

isContaining

public final boolean isContaining(DateRangeI innerRange)
Description copied from interface: DateRangeI
Checks if a 'innerDateSpan' is compleately inside or equal to this range.

Specified by:
isContaining in interface DateRangeI
Parameters:
innerRange - The possibly inside date range
Returns:
If 'innerDateSpan' is compleately inside or equal to this range.

isContaining

public final boolean isContaining(long timeInMillis,
                                  boolean disregardSorting)
Description copied from interface: DateRangeI
Returns if the millisecond is within the range, inclusive.

Specified by:
isContaining in interface DateRangeI
disregardSorting - If true unsorted ranges (start > end) also returns true if timeInMillis is betweend the boundarys
Returns:
If the millisecond is within the range.

getRangeType

public final int getRangeType()
Description copied from interface: DateRangeI
Returns the type of range that this DataSpan spans. (RANGE_TYPE_xxx). This method doesn't handle time of day at all. The smallest range type that can be returned is RANGE_TYPE_DAY and it will do that if the range start and end is in the same day.

Only if one day, one week, one month or one year (week or month based) are exactly spanned (end date inclusive) will anything other than RANGE_TYPE_CUSTOM be returned.

Specified by:
getRangeType in interface DateRangeI
Returns:
The type of range that this DataSpan spans. (RANGE_TYPE_xxx)

getMiddle

public final java.util.Calendar getMiddle()
Description copied from interface: DateRangeI
Calulates the time in the middle of 'startDate' and 'endDate'.

Specified by:
getMiddle in interface DateRangeI
Returns:
The time in the middle of 'startDate' and 'endDate'.

getMiddleMillis

public final long getMiddleMillis()
Description copied from interface: DateRangeI
Calulates the time in the middle of 'startDate' and 'endDate'.

Specified by:
getMiddleMillis in interface DateRangeI
Returns:
The time im millisoconds in the middle of 'startDate' and 'endDate'.

getRelative

public final java.util.Calendar getRelative(double perc)
Description copied from interface: DateRangeI
Returns a date that are perc percent into the range. i.e. if perc is 0.5d, a date exactly between start and end date is returned. 0.0d means start date and 1.0d is the end date/time

Specified by:
getRelative in interface DateRangeI
Parameters:
perc - The percentage.
Returns:
A date that are perc percent in the range.

getRelativeMillis

public long getRelativeMillis(double perc)
Description copied from interface: DateRangeI
Returns a date that are perc percent into the range. i.e. if perc is 0.5d, a date exactly between start and end date is returned. 0.0d means start date and 1.0d is the end date/time

Specified by:
getRelativeMillis in interface DateRangeI
Parameters:
perc - The percentage.
Returns:
A date that are perc percent in the range.

getRelativeRange

public final DateRangeI getRelativeRange(double startPerc,
                                         double endPerc)
Description copied from interface: DateRangeI
Returns a date range that start from startPerc percent into the range until endPerc into the range. If endPerc is 1.0d the last millisecond is returned (since it is inclusive), as opposed to #getRelativeDateRange. If startPerc and endPerc is equal, a range with the same start and end date will be returned.

Specified by:
getRelativeRange in interface DateRangeI
Parameters:
startPerc - A percentage into the range. must be <= endPerc
endPerc - A percentage into the range. must be >= startPerc
Returns:
A date range spanning the relative part of a this date range.

getDurationString

public java.lang.String getDurationString(java.lang.String formatString)
Description copied from interface: DateRangeI
Calls DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for the start and end dates and returns the result.

Specified by:
getDurationString in interface DateRangeI
Parameters:
formatString - The format string. See DateUtil.getDurationString(java.util.Calendar, java.util.Calendar, boolean, String) for details.
Returns:
The resulting string. Not null.

iterator

public final java.util.Iterator iterator(int boundaryType)
Description copied from interface: DateRangeI
Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next(). Every DateRangeI returned will be of the length that 'boundaryType' indicates, except maybe the first and last since these two are NOT rounded to their boundary before starting. If this range's start date and end date are within same 'boundaryType' (eg. week) the iterator will only return one DateRange with range same as 'this'.
This range's start and end dates are read at the initialization of the Iterator and may be changed while using it, without affecting the Iterator or its returned values.
If the date range isn't sorted the iterator will return no ranges as all.

Specified by:
iterator in interface DateRangeI
Parameters:
boundaryType - The "size" that this range will be "chopped" to. 'boundaryType'. RANGE_TYPE_xxx
Returns:
An iterator that iterates over the range.

iterator

public final java.util.Iterator iterator(int boundaryType,
                                         int amount)
Description copied from interface: DateRangeI
Returns an iterator that iterates over the range, returning a new DateRangeI for every call to .next(). Every DateRangeI returned will be of the length that 'boundaryType' indicates, except maybe the first and last since these two are NOT rounded to their boundary before staring. If this range's start date and end date are within same 'boundaryType' (eg. week) the iterator will only return one DateRange with range same as 'this'.
This range's start and end dates are read at the initialization of the Iterator and may be changed while using it, without affecting the Iterator or its returned values.
If the date range isn't sorted the iterator will return no ranges as all.

Specified by:
iterator in interface DateRangeI
Parameters:
boundaryType - The "size" that this range will be "chopped" to (regardless of amount). 'boundaryType'. RANGE_TYPE_xxx
amount - The amount of boundsryType to add for every iteration.
Returns:
An iterator that iterates over the range.

getSubDateList

public final java.util.ArrayList getSubDateList(int field,
                                                int[] values,
                                                int occurField,
                                                int[] dayOfWeekOccur,
                                                int maxCount,
                                                boolean asRanges)
Description copied from interface: DateRangeI
Runs an iterator over the range with sizes field and returns all date/times that's inside this range and which have a field value that is one of the integers in values. E.g. if this range is a month and field is Calendar.DAY_OF_WEEK with values == {0, 1} then all sundays and mondays within this range are returned as GegorianCalendars.

Specified by:
getSubDateList in interface DateRangeI
Parameters:
field - The field in a Calendar. E.g. Calendar.DAY_OF_WEEK.
values - A number of values for field to match. Not null. Can be negative and if so is relative to the maximum possible value of the field. E.g. -1 when field is Calendar.HOUR is same as 23.
occurField - Either Calendar.DAY_OF_YEAR or Calendar.DAY_OF_MONTH. Only used if occurFilter is non-null. field must also be set to Calendar.DAY_OF_WEEK.
dayOfWeekOccur - Specifies for every value that only an occurence within the month or year (depending on occurField) should be returned.
For instance if values[0] == Calendar.MONDAY, occurField == Calendar.DAY_OF_YEAR and dayOfWeekOccur[0] == 2 then only the second monday of the year is considered a "hit". Negative values means "from the end", so dayOfWeekOccur[0] == -2 would mean second to last monday of the year.
An element that is 0 is as usual (as if dayOfWeekOccur == null) considered to be all mondays (for instance).
If non-null must be same length as values, field must be Calendar.DAY_OF_WEEK. If input is a bad combination an IllegalArgumentException is thrown.
See "BYDAY" paragraph in "RFC 2445" for further explanation.
maxCount - The maximum size of the returned list. -1 means no limit. Can be used as a "protection" against bad input that would return to much data.
asRanges - If true the returned List is made up of DateRanges instead of Calendars. These ranges are set to fill the whole boundary that field indicats. E.g. spans exactly a day for Calendar.DAY_OF_MONTH.
Returns:
A list of GegorianCalendar s and/or MutableDateRanges. Never null but can be of size 0.

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String formatString,
                                 boolean endIsExcluding,
                                 boolean includeOffset)
Description copied from interface: DateRangeI
Retuns a string representation of the date range. E.g. "yyyy-MM-dd HH:mm:ss:SSS".

Specified by:
toString in interface DateRangeI
Parameters:
formatString - Format for the dates. If null default date time instance is used.
endIsExcluding - Set to true if the end date should be displayed 'excluding' the last millisecond, normally meaning that the milliseconds are are an even number (0).
includeOffset - If the DST (Daylight Savings Time) offset should be included in the output.
Returns:
The string.

equals

public final boolean equals(java.lang.Object o)
Returns true if obj is != null, is an instance of DateRangeI and represents date range with the same start and end millisecond

Overrides:
equals in class java.lang.Object
Parameters:
o - The other object
Returns:
true if obj is != null and a date range with the same start and end millisecond

compareTo

public final int compareTo(java.lang.Object o)
Compares startdates, and if they are the same, end dates. If .equals() return 0.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The other DateRangeI to compare to. Not null and must be of type DateRangeI
Returns:
-1, 0 or 1.

hashCode

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


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.