Package org.jfree.data.time
Class RegularTimePeriod
java.lang.Object
org.jfree.data.time.RegularTimePeriod
- All Implemented Interfaces:
Comparable
,TimePeriod
,org.jfree.date.MonthConstants
- Direct Known Subclasses:
Day
,FixedMillisecond
,Hour
,Millisecond
,Minute
,Month
,Quarter
,Second
,Week
,Year
public abstract class RegularTimePeriod
extends Object
implements TimePeriod, Comparable, org.jfree.date.MonthConstants
An abstract class representing a unit of time. Convenient methods are
provided for calculating the next and previous time periods. Conversion
methods are defined that return the first and last milliseconds of the time
period. The results from these methods are timezone dependent.
This class is immutable, and all subclasses should be immutable also.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TimeZone
Deprecated.static final Calendar
Deprecated.This was a bad idea, don't use it!Fields inherited from interface org.jfree.date.MonthConstants
APRIL, AUGUST, DECEMBER, FEBRUARY, JANUARY, JULY, JUNE, MARCH, MAY, NOVEMBER, OCTOBER, SEPTEMBER
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RegularTimePeriod
createInstance
(Class c, Date millisecond, TimeZone zone) Creates a time period that includes the specified millisecond, assuming the given time zone.static Class
Returns a subclass ofRegularTimePeriod
that is smaller than the specified class.getEnd()
Returns the date/time that marks the end of the time period.abstract long
Returns the first millisecond of the time period.abstract long
getFirstMillisecond
(Calendar calendar) Returns the first millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).long
getFirstMillisecond
(TimeZone zone) Deprecated.As of 1.0.3, you should avoid using this method (it creates a new Calendar instance every time it is called).abstract long
Returns the last millisecond of the time period.abstract long
getLastMillisecond
(Calendar calendar) Returns the last millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).long
getLastMillisecond
(TimeZone zone) Deprecated.As of 1.0.3, you should avoid using this method (it creates a new Calendar instance every time it is called).long
Returns the millisecond closest to the middle of the time period.long
getMiddleMillisecond
(Calendar calendar) Returns the millisecond closest to the middle of the time period, evaluated using the supplied calendar (which incorporates a timezone).long
getMiddleMillisecond
(TimeZone zone) Deprecated.As of 1.0.3, you should avoid using this method (it creates a new Calendar instance every time it is called).long
getMillisecond
(TimePeriodAnchor anchor, Calendar calendar) Returns the millisecond (relative to the epoch) corresponding to the specifiedanchor
using the suppliedcalendar
(which incorporates a time zone).abstract long
Returns a serial index number for the time unit.getStart()
Returns the date/time that marks the start of the time period.abstract RegularTimePeriod
next()
Returns the time period following this one, ornull
if some limit has been reached.abstract void
Recalculates the start date/time and end date/time for this time period relative to the supplied calendar (which incorporates a time zone).abstract RegularTimePeriod
previous()
Returns the time period preceding this one, ornull
if some lower limit has been reached.toString()
Returns a string representation of the time period.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
DEFAULT_TIME_ZONE
Deprecated.As of 1.0.11, we discourage the use of this field - useTimeZone.getDefault()
instead.The default time zone. -
WORKING_CALENDAR
Deprecated.This was a bad idea, don't use it!A working calendar (recycle to avoid unnecessary object creation).
-
-
Constructor Details
-
RegularTimePeriod
public RegularTimePeriod()
-
-
Method Details
-
createInstance
Creates a time period that includes the specified millisecond, assuming the given time zone.- Parameters:
c
- the time period class.millisecond
- the time.zone
- the time zone.- Returns:
- The time period.
-
downsize
Returns a subclass ofRegularTimePeriod
that is smaller than the specified class.- Parameters:
c
- a subclass ofRegularTimePeriod
.- Returns:
- A class.
-
previous
Returns the time period preceding this one, ornull
if some lower limit has been reached.- Returns:
- The previous time period (possibly
null
).
-
next
Returns the time period following this one, ornull
if some limit has been reached.- Returns:
- The next time period (possibly
null
).
-
getSerialIndex
Returns a serial index number for the time unit.- Returns:
- The serial index number.
-
peg
Recalculates the start date/time and end date/time for this time period relative to the supplied calendar (which incorporates a time zone).- Parameters:
calendar
- the calendar (null
not permitted).- Since:
- 1.0.3
-
getStart
Returns the date/time that marks the start of the time period. This method returns a newDate
instance every time it is called.- Specified by:
getStart
in interfaceTimePeriod
- Returns:
- The start date/time.
- See Also:
-
getEnd
Returns the date/time that marks the end of the time period. This method returns a newDate
instance every time it is called.- Specified by:
getEnd
in interfaceTimePeriod
- Returns:
- The end date/time.
- See Also:
-
getFirstMillisecond
Returns the first millisecond of the time period. This will be determined relative to the time zone specified in the constructor, or in the calendar instance passed in the most recent call to thepeg(Calendar)
method.- Returns:
- The first millisecond of the time period.
- See Also:
-
getFirstMillisecond
Deprecated.As of 1.0.3, you should avoid using this method (it creates a new Calendar instance every time it is called). You are advised to callgetFirstMillisecond(Calendar)
instead.Returns the first millisecond of the time period, evaluated within a specific time zone.- Parameters:
zone
- the time zone (null
not permitted).- Returns:
- The first millisecond of the time period.
- See Also:
-
getFirstMillisecond
Returns the first millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).- Parameters:
calendar
- the calendar (null
not permitted).- Returns:
- The first millisecond of the time period.
- Throws:
NullPointerException
- ifcalendar
isnull
.- See Also:
-
getLastMillisecond
Returns the last millisecond of the time period. This will be determined relative to the time zone specified in the constructor, or in the calendar instance passed in the most recent call to thepeg(Calendar)
method.- Returns:
- The last millisecond of the time period.
- See Also:
-
getLastMillisecond
Deprecated.As of 1.0.3, you should avoid using this method (it creates a new Calendar instance every time it is called). You are advised to callgetLastMillisecond(Calendar)
instead.Returns the last millisecond of the time period, evaluated within a specific time zone.- Parameters:
zone
- the time zone (null
not permitted).- Returns:
- The last millisecond of the time period.
- See Also:
-
getLastMillisecond
Returns the last millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).- Parameters:
calendar
- the calendar (null
not permitted).- Returns:
- The last millisecond of the time period.
- See Also:
-
getMiddleMillisecond
Returns the millisecond closest to the middle of the time period.- Returns:
- The middle millisecond.
-
getMiddleMillisecond
Deprecated.As of 1.0.3, you should avoid using this method (it creates a new Calendar instance every time it is called). You are advised to callgetMiddleMillisecond(Calendar)
instead.Returns the millisecond closest to the middle of the time period, evaluated within a specific time zone.- Parameters:
zone
- the time zone (null
not permitted).- Returns:
- The middle millisecond.
-
getMiddleMillisecond
Returns the millisecond closest to the middle of the time period, evaluated using the supplied calendar (which incorporates a timezone).- Parameters:
calendar
- the calendar.- Returns:
- The middle millisecond.
-
getMillisecond
Returns the millisecond (relative to the epoch) corresponding to the specifiedanchor
using the suppliedcalendar
(which incorporates a time zone).- Parameters:
anchor
- the anchor (null
not permitted).calendar
- the calendar (null
not permitted).- Returns:
- Milliseconds since the epoch.
- Since:
- 1.0.18
-
toString
Returns a string representation of the time period.
-
TimeZone.getDefault()
instead.