Package org.jfree.data.time
Class RegularTimePeriod
- java.lang.Object
-
- org.jfree.data.time.RegularTimePeriod
-
- All Implemented Interfaces:
java.lang.Comparable,TimePeriod,org.jfree.date.MonthConstants
- Direct Known Subclasses:
Day,FixedMillisecond,Hour,Millisecond,Minute,Month,Quarter,Second,Week,Year
public abstract class RegularTimePeriod extends java.lang.Object implements TimePeriod, java.lang.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
Fields Modifier and Type Field Description static java.util.TimeZoneDEFAULT_TIME_ZONEDeprecated.As of 1.0.11, we discourage the use of this field - useTimeZone.getDefault()instead.static java.util.CalendarWORKING_CALENDARDeprecated.This was a bad idea, don't use it!
-
Constructor Summary
Constructors Constructor Description RegularTimePeriod()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static RegularTimePeriodcreateInstance(java.lang.Class c, java.util.Date millisecond, java.util.TimeZone zone)Creates a time period that includes the specified millisecond, assuming the given time zone.static java.lang.Classdownsize(java.lang.Class c)Returns a subclass ofRegularTimePeriodthat is smaller than the specified class.java.util.DategetEnd()Returns the date/time that marks the end of the time period.abstract longgetFirstMillisecond()Returns the first millisecond of the time period.abstract longgetFirstMillisecond(java.util.Calendar calendar)Returns the first millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).longgetFirstMillisecond(java.util.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 longgetLastMillisecond()Returns the last millisecond of the time period.abstract longgetLastMillisecond(java.util.Calendar calendar)Returns the last millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).longgetLastMillisecond(java.util.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).longgetMiddleMillisecond()Returns the millisecond closest to the middle of the time period.longgetMiddleMillisecond(java.util.Calendar calendar)Returns the millisecond closest to the middle of the time period, evaluated using the supplied calendar (which incorporates a timezone).longgetMiddleMillisecond(java.util.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).longgetMillisecond(TimePeriodAnchor anchor, java.util.Calendar calendar)Returns the millisecond (relative to the epoch) corresponding to the specifiedanchorusing the suppliedcalendar(which incorporates a time zone).abstract longgetSerialIndex()Returns a serial index number for the time unit.java.util.DategetStart()Returns the date/time that marks the start of the time period.abstract RegularTimePeriodnext()Returns the time period following this one, ornullif some limit has been reached.abstract voidpeg(java.util.Calendar calendar)Recalculates the start date/time and end date/time for this time period relative to the supplied calendar (which incorporates a time zone).abstract RegularTimePeriodprevious()Returns the time period preceding this one, ornullif some lower limit has been reached.java.lang.StringtoString()Returns a string representation of the time period.
-
-
-
Field Detail
-
DEFAULT_TIME_ZONE
public static final java.util.TimeZone 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
public static final java.util.Calendar WORKING_CALENDAR
Deprecated.This was a bad idea, don't use it!A working calendar (recycle to avoid unnecessary object creation).
-
-
Constructor Detail
-
RegularTimePeriod
public RegularTimePeriod()
-
-
Method Detail
-
createInstance
public static RegularTimePeriod createInstance(java.lang.Class c, java.util.Date millisecond, java.util.TimeZone zone)
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
public static java.lang.Class downsize(java.lang.Class c)
Returns a subclass ofRegularTimePeriodthat is smaller than the specified class.- Parameters:
c- a subclass ofRegularTimePeriod.- Returns:
- A class.
-
previous
public abstract RegularTimePeriod previous()
Returns the time period preceding this one, ornullif some lower limit has been reached.- Returns:
- The previous time period (possibly
null).
-
next
public abstract RegularTimePeriod next()
Returns the time period following this one, ornullif some limit has been reached.- Returns:
- The next time period (possibly
null).
-
getSerialIndex
public abstract long getSerialIndex()
Returns a serial index number for the time unit.- Returns:
- The serial index number.
-
peg
public abstract void peg(java.util.Calendar calendar)
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 (nullnot permitted).- Since:
- 1.0.3
-
getStart
public java.util.Date getStart()
Returns the date/time that marks the start of the time period. This method returns a newDateinstance every time it is called.- Specified by:
getStartin interfaceTimePeriod- Returns:
- The start date/time.
- See Also:
getFirstMillisecond()
-
getEnd
public java.util.Date getEnd()
Returns the date/time that marks the end of the time period. This method returns a newDateinstance every time it is called.- Specified by:
getEndin interfaceTimePeriod- Returns:
- The end date/time.
- See Also:
getLastMillisecond()
-
getFirstMillisecond
public abstract long 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:
getLastMillisecond()
-
getFirstMillisecond
public long getFirstMillisecond(java.util.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). 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 (nullnot permitted).- Returns:
- The first millisecond of the time period.
- See Also:
getLastMillisecond(TimeZone)
-
getFirstMillisecond
public abstract long getFirstMillisecond(java.util.Calendar calendar)
Returns the first millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).- Parameters:
calendar- the calendar (nullnot permitted).- Returns:
- The first millisecond of the time period.
- Throws:
java.lang.NullPointerException- ifcalendarisnull.- See Also:
getLastMillisecond(Calendar)
-
getLastMillisecond
public abstract long 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:
getFirstMillisecond()
-
getLastMillisecond
public long getLastMillisecond(java.util.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). 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 (nullnot permitted).- Returns:
- The last millisecond of the time period.
- See Also:
getFirstMillisecond(TimeZone)
-
getLastMillisecond
public abstract long getLastMillisecond(java.util.Calendar calendar)
Returns the last millisecond of the time period, evaluated using the supplied calendar (which incorporates a timezone).- Parameters:
calendar- the calendar (nullnot permitted).- Returns:
- The last millisecond of the time period.
- See Also:
getFirstMillisecond(Calendar)
-
getMiddleMillisecond
public long getMiddleMillisecond()
Returns the millisecond closest to the middle of the time period.- Returns:
- The middle millisecond.
-
getMiddleMillisecond
public long getMiddleMillisecond(java.util.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). 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 (nullnot permitted).- Returns:
- The middle millisecond.
-
getMiddleMillisecond
public long getMiddleMillisecond(java.util.Calendar calendar)
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
public long getMillisecond(TimePeriodAnchor anchor, java.util.Calendar calendar)
Returns the millisecond (relative to the epoch) corresponding to the specifiedanchorusing the suppliedcalendar(which incorporates a time zone).- Parameters:
anchor- the anchor (nullnot permitted).calendar- the calendar (nullnot permitted).- Returns:
- Milliseconds since the epoch.
- Since:
- 1.0.18
-
toString
public java.lang.String toString()
Returns a string representation of the time period.- Overrides:
toStringin classjava.lang.Object- Returns:
- The string.
-
-