Interface TimeFrame


public interface TimeFrame
Time frame.

Belongs to a TimeFrameSet. The default set is TimeFrames.CORE; to create custom time frame sets, call TimeFrameSet.builder().

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether this frame can roll up to toFrame.
    default int
    Returns a date where this time frame is at the start of a cycle.
    Returns the time frame set that this frame belongs to.
    default int
    Returns a month number where this time frame is at the start of a cycle.
    Name of this time frame.
    @Nullable org.apache.commons.math3.fraction.BigFraction
    per(TimeFrame timeFrame)
    If this time frame has units in common with another time frame, returns the number of this time frame in one of that time frame.
    default long
    Returns a timestamp where this time frame is at the start of a cycle.
    default @Nullable org.apache.calcite.avatica.util.TimeUnit
    Returns the built-in unit of this frame, or null if it does not correspond to a built-in unit.
  • Method Details

    • frameSet

      TimeFrameSet frameSet()
      Returns the time frame set that this frame belongs to.
    • name

      String name()
      Name of this time frame.

      A time frame based on a built-in Avatica TimeUnit will have the same name.

      See Also:
    • per

      @Nullable org.apache.commons.math3.fraction.BigFraction per(TimeFrame timeFrame)
      If this time frame has units in common with another time frame, returns the number of this time frame in one of that time frame.

      For example, MONTH.per(YEAR) returns 12; YEAR.per(MONTH) returns 1 / 12.

    • dateEpoch

      default int dateEpoch()
      Returns a date where this time frame is at the start of a cycle.

      For example, the WEEK time frame starts on a Monday, and 1970-01-05 was a Monday, and the date 1970-01-05 is represented as integer 5, so for the WEEK time frame this method returns 5. But it would also be valid to return the date value of 1900/01/01, which was also a Monday. Because we know that a week is 7 days, we can compute every other point at which a week advances.

    • timestampEpoch

      default long timestampEpoch()
      Returns a timestamp where this time frame is at the start of a cycle.
      See Also:
    • monthEpoch

      default int monthEpoch()
      Returns a month number where this time frame is at the start of a cycle.
      See Also:
    • canRollUpTo

      boolean canRollUpTo(TimeFrame toFrame)
      Whether this frame can roll up to toFrame.

      Examples:

      • SECOND can roll up to MINUTE, HOUR, DAY, WEEK, MONTH, MILLENNIUM;
      • SECOND cannot roll up to MILLISECOND (because it is finer grained);
      • WEEK cannot roll up to MONTH, YEAR, MILLENNIUM (because weeks cross month boundaries).

      If two time frames have the same core, and one is an integer simple multiple of another, and they have the same offset, then they can roll up. For example, suppose that MINUTE15 and HOUR3 are both based on SECOND; MINUTE15 is 15 * 60 seconds and HOUR3 is 3 * 60 * 60 seconds; therefore one HOUR3 interval equals twelve MINUTE15 intervals. They have the same offset (both start at 1970-01-01 00:00:00) and therefore MINUTE15 can roll up to HOUR3.

      Even if two frames are not multiples, if they are aligned then they can roll up. MONTH and DAY are an example. For more about alignment, see TimeFrameSet.Builder.addRollup(String, String).

    • unit

      default @Nullable org.apache.calcite.avatica.util.TimeUnit unit()
      Returns the built-in unit of this frame, or null if it does not correspond to a built-in unit.