Class TimeString

All Implemented Interfaces:

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(1970, 1, 1, 2, 3, 4).withMillis(56) yields TIME '1970-01-01 02:03:04.056'.

    • 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(1970, 1, 1, 2, 3, 4).withNanos(56789) yields TIME '1970-01-01 02:03:04.000056789'.

    • 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(1970, 1, 1, 2, 3, 4).withFraction("00506000") yields TIME '1970-01-01 02:03:04.00506'.

    • toString

      public String toString()
      toString in class Object
    • equals

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

      public int hashCode()
      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.