Class TimestampString

  • All Implemented Interfaces:
    java.lang.Comparable<TimestampString>

    public class TimestampString
    extends java.lang.Object
    implements java.lang.Comparable<TimestampString>
    Timestamp literal.

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

    • Field Detail

      • PATTERN

        private static final java.util.regex.Pattern PATTERN
      • v

        final java.lang.String v
    • Constructor Detail

      • TimestampString

        public TimestampString​(java.lang.String v)
        Creates a TimeString.
      • TimestampString

        public TimestampString​(int year,
                               int month,
                               int day,
                               int h,
                               int m,
                               int s)
        Creates a TimestampString for year, month, day, hour, minute, second, millisecond values.
    • Method Detail

      • withMillis

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

        For example, new TimestampString(1970, 1, 1, 2, 3, 4).withMillis(56) yields TIMESTAMP '1970-01-01 02:03:04.056'.

      • withNanos

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

        For example, new TimestampString(1970, 1, 1, 2, 3, 4).withNanos(56789) yields TIMESTAMP '1970-01-01 02:03:04.000056789'.

      • withFraction

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

        For example, new TimestampString(1970, 1, 1, 2, 3, 4).withFraction("00506000") yields TIMESTAMP '1970-01-01 02:03:04.00506'.

      • toString

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

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • fromCalendarFields

        public static TimestampString fromCalendarFields​(java.util.Calendar calendar)
        Creates a TimestampString from a Calendar.
      • getMillisSinceEpoch

        public long getMillisSinceEpoch()
        Returns the number of milliseconds since the epoch.
      • getMillisInSecond

        private int getMillisInSecond()
      • fromMillisSinceEpoch

        public static TimestampString fromMillisSinceEpoch​(long millis)
        Creates a TimestampString that is a given number of milliseconds since the epoch.
      • toCalendar

        public java.util.Calendar toCalendar()
      • toString

        public java.lang.String toString​(int precision)
        Converts this TimestampString to a string, truncated or padded with zeroes to a given precision.
      • precision

        private int precision()