Class RegularTimePeriod

java.lang.Object
org.jfree.data.time.RegularTimePeriod
All Implemented Interfaces:
Comparable, MonthConstants, TimePeriod
Direct Known Subclasses:
Day, FixedMillisecond, Hour, Millisecond, Minute, Month, Quarter, Second, Week, Year

public abstract class RegularTimePeriod
extends Object
implements TimePeriod, Comparable, 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.

  • Constructor Details

  • Method Details

    • createInstance

      public static RegularTimePeriod createInstance​(Class c, Date millisecond, TimeZone zone, Locale locale)
      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.
      locale - the locale.
      Returns:
      The time period.
    • downsize

      public static Class downsize​(Class c)
      Returns a subclass of RegularTimePeriod that is smaller than the specified class.
      Parameters:
      c - a subclass of RegularTimePeriod.
      Returns:
      A class.
    • previous

      public abstract RegularTimePeriod previous()
      Returns the time period preceding this one, or null if 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, or null if 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​(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 (null not permitted).
      Since:
      1.0.3
    • getStart

      public Date getStart()
      Returns the date/time that marks the start of the time period. This method returns a new Date instance every time it is called.
      Specified by:
      getStart in interface TimePeriod
      Returns:
      The start date/time.
      See Also:
      getFirstMillisecond()
    • getEnd

      public Date getEnd()
      Returns the date/time that marks the end of the time period. This method returns a new Date instance every time it is called.
      Specified by:
      getEnd in interface TimePeriod
      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 the peg(Calendar) method.
      Returns:
      The first millisecond of the time period.
      See Also:
      getLastMillisecond()
    • getFirstMillisecond

      public abstract long getFirstMillisecond​(Calendar calendar)
      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 - if calendar is null.
      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 the peg(Calendar) method.
      Returns:
      The last millisecond of the time period.
      See Also:
      getFirstMillisecond()
    • getLastMillisecond

      public abstract long getLastMillisecond​(Calendar calendar)
      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:
      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​(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, Calendar calendar)
      Returns the millisecond (relative to the epoch) corresponding to the specified anchor using the supplied calendar (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

      public String toString()
      Returns a string representation of the time period.
      Overrides:
      toString in class Object
      Returns:
      The string.