Class TimeString

java.lang.Object
org.apache.calcite.util.TimeString
All Implemented Interfaces:
Comparable<TimeString>

public class TimeString extends Object implements Comparable<TimeString>
Time literal.

Immutable, internally represented as a string (in ISO format), and can support unlimited precision (milliseconds, nanoseconds).

  • Constructor Details

    • TimeString

      public TimeString(String v)
      Creates a TimeString.
    • TimeString

      public TimeString(int h, int m, int s)
      Creates a TimeString for hour, minute, second and millisecond values.
  • Method Details

    • withMillis

      public TimeString withMillis(int millis)
      Sets the fraction field of a TimeString to a given number of milliseconds. Nukes the value set via withNanos(int).

      For example, new TimeString(2, 3, 4).withMillis(56) yields TIME '02:03:04.056'.

      Throws:
      IllegalArgumentException - if millis is outside the allowed range
    • withNanos

      public TimeString withNanos(int nanos)
      Sets the fraction field of a TimeString to a given number of nanoseconds. Nukes the value set via withMillis(int).

      For example, new TimeString(2, 3, 4).withNanos(56789) yields TIME '02:03:04.000056789'.

      Throws:
      IllegalArgumentException - if nanos is outside the allowed range
    • withFraction

      public TimeString withFraction(String fraction)
      Sets the fraction field of a TimeString. The precision is determined by the number of leading zeros. Trailing zeros are stripped.

      For example, new TimeString(2, 3, 4).withFraction("00506000") yields TIME '02:03:04.00506'.

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(TimeString o)
      Specified by:
      compareTo in interface Comparable<TimeString>
    • fromCalendarFields

      public static TimeString fromCalendarFields(Calendar calendar)
      Creates a TimeString from a Calendar.
    • fromMillisOfDay

      public static TimeString fromMillisOfDay(int i)
    • round

      public TimeString round(int precision)
    • getMillisOfDay

      public int getMillisOfDay()
    • toCalendar

      public Calendar toCalendar()
    • toString

      public String toString(int precision)
      Converts this TimestampString to a string, truncated or padded with zeros to a given precision.