Class Rounding

java.lang.Object
org.opensearch.common.Rounding
All Implemented Interfaces:
org.opensearch.core.common.io.stream.Writeable

@PublicApi(since="1.0.0") public abstract class Rounding extends Object implements org.opensearch.core.common.io.stream.Writeable
A strategy for rounding milliseconds since epoch.

There are two implementations for rounding. The first one requires a date time unit and rounds to the supplied date time unit (i.e. quarter of year, day of month). The second one allows you to specify an interval to round to.

See this blog for some background reading. Its super interesting and the links are a comedy gold mine. If you like time zones. Or hate them.

Opensearch.api:
  • Constructor Details Link icon

    • Rounding Link icon

      public Rounding()
  • Method Details Link icon

    • innerWriteTo Link icon

      public abstract void innerWriteTo(org.opensearch.core.common.io.stream.StreamOutput out) throws IOException
      Throws:
      IOException
    • writeTo Link icon

      public void writeTo(org.opensearch.core.common.io.stream.StreamOutput out) throws IOException
      Specified by:
      writeTo in interface org.opensearch.core.common.io.stream.Writeable
      Throws:
      IOException
    • id Link icon

      public abstract byte id()
    • prepare Link icon

      public abstract Rounding.Prepared prepare(long minUtcMillis, long maxUtcMillis)
      Prepare to round many times.
    • prepareForUnknown Link icon

      public abstract Rounding.Prepared prepareForUnknown()
      Prepare to round many dates over an unknown range. Prefer prepare(long, long) if you can find the range because it'll be much more efficient.
    • round Link icon

      @Deprecated public final long round(long utcMillis)
      Rounds the given value.
    • nextRoundingValue Link icon

      @Deprecated public final long nextRoundingValue(long utcMillis)
      Given the rounded value (which was potentially generated by round(long), returns the next rounding value. For example, with interval based rounding, if the interval is 3, nextRoundValue(6) = 9.
    • offset Link icon

      @Deprecated public abstract long offset()
      Deprecated.
      We're in the process of abstracting offset *into* Rounding so keep any usage to migratory shims
      How "offset" this rounding is from the traditional "start" of the period.
    • withoutOffset Link icon

      public abstract Rounding withoutOffset()
      Strip the offset from these bounds.
    • equals Link icon

      public abstract boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode Link icon

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • builder Link icon

      public static Rounding.Builder builder(Rounding.DateTimeUnit unit)
    • builder Link icon

      public static Rounding.Builder builder(org.opensearch.common.unit.TimeValue interval)
    • read Link icon

      public static Rounding read(org.opensearch.core.common.io.stream.StreamInput in) throws IOException
      Throws:
      IOException
    • getInterval Link icon

      public static OptionalLong getInterval(Rounding rounding)
      Extracts the interval value from the Rounding instance
      Parameters:
      rounding - Rounding instance
      Returns:
      the interval value from the Rounding instance or OptionalLong.empty() if the interval is not available