public class TimeSpan extends Object
Time spans are expressed as a combination of time units and their associated
amounts. Each amount may add up to be more than one of a larger time unit.
For example a time unit may be expressed as 1 month and 6 weeks. Time
amounts that are not used should be set to 0, e.g. a time span representing a
single day would have only days
set to 1 and all other time units as
0.
Note that when the overloaded Date
and long
methods are used,
the instances are converted to the JVM's current calendar system. This may
have a slight, noticeable affect due to daylight savings or any other
calendar-specific differences to how a date is calculated.
Constructor and Description |
---|
TimeSpan(int years,
int months,
int weeks,
int days,
int hours)
Creates a time span for the specified duration.
|
TimeSpan(String timespan)
Creates a time span using the date string to specify the time units and
amounts.
|
Modifier and Type | Method and Description |
---|---|
int |
getDays()
Returns the day component of this time span.
|
int |
getHours()
Returns the hour component of this time span.
|
int |
getMonths()
Returns the month component of this time span.
|
int |
getWeeks()
Returns the week component of this time span.
|
int |
getYears()
Returns the year component of this time span.
|
boolean |
insideRange(Calendar startDate,
Calendar endDate)
Returns
true if the end date occurs after the start date during
the period of time represented by this time span. |
boolean |
insideRange(Date startDate,
Date endDate)
Returns
true if the end date occurs after the start date during
the period of time represented by this time span. |
boolean |
insideRange(long startDate,
long endDate)
Returns
true if the end date occurs after the start date during
the period of time represented by this time span. |
String |
toString() |
public TimeSpan(String timespan)
y
for year, m
for month.timespan
- a string containing numbers each followed by a single
character to denote the time unitIllegalArgumentException
- if public TimeSpan(int years, int months, int weeks, int days, int hours)
years
- the number of years for this time spanmonths
- the number of years for this time spanweeks
- the number of years for this time spandays
- the number of years for this time spanhours
- the number of years for this time spanIllegalArgumentException
- if any of the parameters are negativepublic int getDays()
public int getHours()
public int getMonths()
public int getWeeks()
public int getYears()
public boolean insideRange(Calendar startDate, Calendar endDate)
true
if the end date occurs after the start date during
the period of time represented by this time span.public boolean insideRange(Date startDate, Date endDate)
true
if the end date occurs after the start date during
the period of time represented by this time span.public boolean insideRange(long startDate, long endDate)
true
if the end date occurs after the start date during
the period of time represented by this time span.Copyright © 2012. All Rights Reserved.