public class TimeSpan extends Object implements ITimeSpan
ITimeSpan
interface.Modifier and Type | Field and Description |
---|---|
static TimeSpan |
ALL
A time span, which covers the entire possible horizon from time point 0
until
Long.MAX_VALUE . |
static ITimeSpan |
DEFAULT_TIME_SPAN
Stores a default time span instance, where the start time is the current
system time and the end time is the current system time plus one year.
|
static TimeSpan |
UNDEFINED
An undefined time span, which gets used in various algorithms to express
that no valid time span has been calculated, yet.
|
Constructor and Description |
---|
TimeSpan()
Constructs a new time span where the start and end time are equal to
zero.
|
TimeSpan(Calendar time)
Constructs a new time span where the start and end times are equal to the
milliseconds of the given calendar object.
|
TimeSpan(Calendar start,
Calendar end)
Constructs a new time span where the start and end times are based on the
given calendar objects.
|
TimeSpan(Date date)
Constructs a new time span where the start and end times are equal to the
give date.
|
TimeSpan(Date start,
Date end)
Constructs a new time span with the given start and end dates.
|
TimeSpan(int year,
int month,
int date)
Constructs a new time point for the given year, month and date.
|
TimeSpan(int startYear,
int startMonth,
int startDate,
int endYear,
int endMonth,
int endDate)
Constructs a new time span for the given year, month and date.
|
TimeSpan(int startYear,
int startMonth,
int startDate,
int endYear,
int endMonth,
int endDate,
TimeZone timeZone)
Constructs a new time span for the given year, month and date.
|
TimeSpan(int year,
int month,
int date,
TimeZone timeZone)
Constructs a new time point for the given year, month and date.
|
TimeSpan(ITimeSpan span)
Constructs a new time span based on an already existing time span.
|
TimeSpan(long time)
Constructs a new time span where the start time and the end time are both
equal to given time.
|
TimeSpan(long start,
long end)
Constructs a new time span with the given start and end.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ITimeSpan span) |
boolean |
contains(ITimeSpan span)
Checks whether the time span contains the given time span.
|
boolean |
contains(long time)
Checks whether the time span contains the given time point.
|
boolean |
endsAfter(ITimeSpan span)
Checks whether the given time span ends after this time span.
|
boolean |
endsBefore(ITimeSpan span)
Checks whether the given time span ends before this time span.
|
boolean |
equalDuration(ITimeSpan span)
Checks whether the given time span has exactly the same duration as this
time span.
|
boolean |
equals(ITimeSpan span)
Two time spans are considered equal if their start times and their end
times are identical.
|
boolean |
equals(Object o) |
long |
getDuration()
Calculates the total duration of this time span.
|
Calendar |
getEndCalendar()
Returns a new calendar object based on the current end time.
|
Calendar |
getEndCalendar(TimeZone timeZone)
Returns a new calendar object based on the current end time.
|
Date |
getEndDate()
Returns a new date object based on the current end time.
|
long |
getEndTime()
Returns the time span's end time.
|
Calendar |
getStartCalendar()
Returns a new calendar object based on the current start time.
|
Calendar |
getStartCalendar(TimeZone timeZone)
Returns a new calendar object based on the current start time.
|
Date |
getStartDate()
Returns a new date object based on the current start time.
|
long |
getStartTime()
Returns the time span's start time.
|
ITimeSpan |
intersection(ITimeSpan span)
Returns the intersection between the time span and the given time span.
|
boolean |
intersects(ITimeSpan span)
Checks whether the given time span intersects with this time span.
|
boolean |
isActivity()
Determines whether this time span represents an activity.
|
boolean |
isEvent()
Determines whether this time span represents an event.
|
boolean |
isUndefined()
Checks whether this time span is undefined.
|
TimeSpan |
move(long delta)
Constructs a new time span based on this span where the given (delta)
milliseconds are added to (or subtracted from if negative) the start and
end time of this time span.
|
boolean |
startsAfter(ITimeSpan span)
Checks whether the given time span starts after this time span.
|
boolean |
startsBefore(ITimeSpan span)
Checks whether the given time span starts before this time span.
|
String |
toString() |
String |
toString(DateFormat format)
Returns a compact string representation of the time span.
|
ITimeSpan |
union(ITimeSpan span)
The union of two time spans is a new time span, where the start time of
the new span is the minimum start time and the end time is the maximum
end time of the two spans.
|
public static final TimeSpan UNDEFINED
public static final TimeSpan ALL
Long.MAX_VALUE
.public static final ITimeSpan DEFAULT_TIME_SPAN
public TimeSpan(long start, long end)
start
- the start time of the time spanend
- the end time of the time spanpublic TimeSpan(long time)
time
- the start and end time of the time spanpublic TimeSpan(ITimeSpan span)
span
- the original time spanpublic TimeSpan(Date start, Date end)
start
- the start time of the time spanend
- the end time of the time spanDate.getTime()
public TimeSpan(Date date)
date
- the start and end date of the time spanDate.getTime()
public TimeSpan(Calendar start, Calendar end)
start
- the start time of the time spanend
- the end time of the time spanCalendar.getTimeInMillis()
public TimeSpan(Calendar time)
time
- the start and end time of the time spanCalendar.getTimeInMillis()
public TimeSpan(int year, int month, int date, TimeZone timeZone)
year
- the year of the time pointmonth
- the month of the time point (note: months start with 0,
January = 0)date
- the day of the time pointtimeZone
- the time zone for which to create a time spanpublic TimeSpan(int year, int month, int date)
year
- the year of the time pointmonth
- the month of the time point (note: months start with 0,
January = 0)date
- the day of the time pointpublic TimeSpan(int startYear, int startMonth, int startDate, int endYear, int endMonth, int endDate, TimeZone timeZone)
startYear
- the start year of the time spanstartMonth
- the start month of the time span (note: months start with 0,
January = 0)startDate
- the start date of the time spanendYear
- the end year of the time spanendMonth
- the end month of the time span (note: months start with 0,
January = 0)endDate
- the end date of the time spantimeZone
- the time zone for which to create a time spanpublic TimeSpan(int startYear, int startMonth, int startDate, int endYear, int endMonth, int endDate)
startYear
- the start year of the time spanstartMonth
- the start month of the time span (note: months start with 0,
January = 0)startDate
- the start date of the time spanendYear
- the end year of the time spanendMonth
- the end month of the time span (note: months start with 0,
January = 0)endDate
- the end date of the time spanpublic TimeSpan()
public long getStartTime()
ITimeSpan
getStartTime
in interface ITimeSpan
ITimeSpan.getEndTime()
public Date getStartDate()
Date
public Calendar getStartCalendar()
Calendar
getStartTime()
,
getStartDate()
public Calendar getStartCalendar(TimeZone timeZone)
timeZone
- the time zone to useCalendar
getStartTime()
,
getStartDate()
public long getEndTime()
ITimeSpan
getEndTime
in interface ITimeSpan
ITimeSpan.getStartTime()
public Date getEndDate()
Date
getEndTime()
,
getEndCalendar()
public Calendar getEndCalendar()
Calendar
getEndTime()
,
getEndDate()
public Calendar getEndCalendar(TimeZone timeZone)
timeZone
- the time zone to useCalendar
getEndTime()
,
getEndDate()
public int compareTo(ITimeSpan span)
compareTo
in interface Comparable<ITimeSpan>
public boolean contains(ITimeSpan span)
ITimeSpan
contains
in interface ITimeSpan
span
- the time span to test for containmentITimeSpan.intersects(ITimeSpan)
public boolean contains(long time)
ITimeSpan
contains
in interface ITimeSpan
time
- the time point to test for containmentITimeSpan.contains(ITimeSpan)
,
ITimeSpan.intersects(ITimeSpan)
public boolean endsAfter(ITimeSpan span)
ITimeSpan
endsAfter
in interface ITimeSpan
span
- the time span to testITimeSpan.endsBefore(ITimeSpan)
public boolean endsBefore(ITimeSpan span)
ITimeSpan
endsBefore
in interface ITimeSpan
span
- the time span to testITimeSpan.endsAfter(ITimeSpan)
public boolean equalDuration(ITimeSpan span)
ITimeSpan
equalDuration
in interface ITimeSpan
span
- the time span to testITimeSpan.getDuration()
public long getDuration()
ITimeSpan
getDuration
in interface ITimeSpan
ITimeSpan.equalDuration(ITimeSpan)
public boolean intersects(ITimeSpan span)
ITimeSpan
intersects
in interface ITimeSpan
span
- the time span to test for intersectionITimeSpan.contains(ITimeSpan)
public ITimeSpan intersection(ITimeSpan span)
ITimeSpan
ITimeSpan.isUndefined()
) if the two
time spans do not intersect at all.intersection
in interface ITimeSpan
span
- the time span for which to calculate the intersectionpublic boolean isActivity()
ITimeSpan
isActivity
in interface ITimeSpan
ITimeSpan.isEvent()
public boolean isEvent()
ITimeSpan
isEvent
in interface ITimeSpan
ITimeSpan.isEvent()
public TimeSpan move(long delta)
ITimeSpan
public boolean startsAfter(ITimeSpan span)
ITimeSpan
startsAfter
in interface ITimeSpan
span
- the time span to testITimeSpan.startsBefore(ITimeSpan)
public boolean startsBefore(ITimeSpan span)
ITimeSpan
startsBefore
in interface ITimeSpan
span
- the time span to testITimeSpan.startsAfter(ITimeSpan)
public ITimeSpan union(ITimeSpan span)
ITimeSpan
ITimeSpan.isUndefined()
). If only one of
the spans is undefined then the other span becomes the result of the
union operation. If both of them are undefined then the result will be
undefined, too.public boolean isUndefined()
ITimeSpan
ITimeSpan.union(ITimeSpan)
first checks
whether the span on which the method gets called is undefined. If so and
the given second time span is not undefined then the result of the union
operation will be a copy of the second span).isUndefined
in interface ITimeSpan
public boolean equals(ITimeSpan span)
ITimeSpan
public String toString(DateFormat format)
ITimeSpan
Copyright © 2006–2020 Dirk Lemmermann Software & Consulting. All rights reserved.