Record Class RelativeDuration

java.lang.Object
java.lang.Record
org.apache.juneau.commons.beanquery.RelativeDuration
Record Components:
amount - The signed magnitude; negative is in the past, positive is in the future, relative to request time.
unit - The time unit. Must not be null.

public record RelativeDuration(long amount, RelativeDuration.Unit unit) extends Record
A signed, relative-to-request-time duration value: wire literal [+-]<n>(ms|s|m|h|d) (a request-time offset that stays a plain literal on the wire).

Pass one to any BeanQuery.Builder/BeanQuery.GroupBuilder comparison method (eq, ne, gt, gte, lt, lte, between) on a TIMESTAMP or numeric-duration column to mean "relative to the time the request is evaluated" — for example -24 H for "24 hours before now." ValueFormat renders this to the exact wire literal below; the search parser reads that literal back out of a hand-written or stored search string (on a BOOLEAN column it is BAD_VALUE; on TEXT, ID, ENUM and VERSION columns the text is kept literally), and the query engine resolves it against one request-time instant captured once per query (not now()/interval in generated SQL): a TIMESTAMP column's literal becomes instant &plusmn; duration, a numeric-duration column's becomes a plain signed-milliseconds number. This type is the shared, stable wire format the builder, parser, and engines meet at.

Example:

// matches rows whose lastSeen is within the last 24 hours BeanQuery q = BeanQuery.create() .gte("lastSeen", RelativeDuration.ofHours(-24)) .build(); // q.getSearch() == "lastSeen=$gte(\"-24h\")"

Since:
10.0.0
  • Constructor Details

    • RelativeDuration

      public RelativeDuration(long amount, RelativeDuration.Unit unit)
      Compact constructor — validates unit is non-null.
      Parameters:
      amount - The signed magnitude.
      unit - The time unit. Must not be null.
  • Method Details

    • of

      public static RelativeDuration of(long amount, RelativeDuration.Unit unit)
      Creates a relative-duration literal.
      Parameters:
      amount - The signed magnitude; negative is in the past, positive is in the future.
      unit - The time unit. Must not be null.
      Returns:
      The new literal.
    • ofMillis

      public static RelativeDuration ofMillis(long amount)
      Shorthand for of(amount, Unit.MS).
      Parameters:
      amount - The signed magnitude.
      Returns:
      The new literal.
    • ofSeconds

      public static RelativeDuration ofSeconds(long amount)
      Shorthand for of(amount, Unit.S).
      Parameters:
      amount - The signed magnitude.
      Returns:
      The new literal.
    • ofMinutes

      public static RelativeDuration ofMinutes(long amount)
      Shorthand for of(amount, Unit.M).
      Parameters:
      amount - The signed magnitude.
      Returns:
      The new literal.
    • ofHours

      public static RelativeDuration ofHours(long amount)
      Shorthand for of(amount, Unit.H).
      Parameters:
      amount - The signed magnitude.
      Returns:
      The new literal.
    • ofDays

      public static RelativeDuration ofDays(long amount)
      Shorthand for of(amount, Unit.D).
      Parameters:
      amount - The signed magnitude.
      Returns:
      The new literal.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • amount

      public long amount()
      Returns the value of the amount record component.
      Returns:
      the value of the amount record component
    • unit

      Returns the value of the unit record component.
      Returns:
      the value of the unit record component