Package org.apache.calcite.util
Class TimestampString
- java.lang.Object
-
- org.apache.calcite.util.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).
-
-
Constructor Summary
Constructors Constructor Description 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.TimestampString(java.lang.String v)
Creates a TimeString.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(TimestampString o)
boolean
equals(java.lang.Object o)
static TimestampString
fromCalendarFields(java.util.Calendar calendar)
Creates a TimestampString from a Calendar.static TimestampString
fromMillisSinceEpoch(long millis)
Creates a TimestampString that is a given number of milliseconds since the epoch.private int
getMillisInSecond()
long
getMillisSinceEpoch()
Returns the number of milliseconds since the epoch.int
hashCode()
private int
precision()
TimestampString
round(int precision)
java.util.Calendar
toCalendar()
java.lang.String
toString()
java.lang.String
toString(int precision)
Converts this TimestampString to a string, truncated or padded with zeroes to a given precision.TimestampString
withFraction(java.lang.String fraction)
Sets the fraction field of aTimestampString
.TimestampString
withMillis(int millis)
Sets the fraction field of aTimestampString
to a given number of milliseconds.TimestampString
withNanos(int nanos)
Sets the fraction field of aTimestampString
to a given number of nanoseconds.
-
-
-
Method Detail
-
withMillis
public TimestampString withMillis(int millis)
Sets the fraction field of aTimestampString
to a given number of milliseconds. Nukes the value set viawithNanos(int)
.For example,
new TimestampString(1970, 1, 1, 2, 3, 4).withMillis(56)
yieldsTIMESTAMP '1970-01-01 02:03:04.056'
.
-
withNanos
public TimestampString withNanos(int nanos)
Sets the fraction field of aTimestampString
to a given number of nanoseconds. Nukes the value set viawithMillis(int)
.For example,
new TimestampString(1970, 1, 1, 2, 3, 4).withNanos(56789)
yieldsTIMESTAMP '1970-01-01 02:03:04.000056789'
.
-
withFraction
public TimestampString withFraction(java.lang.String fraction)
Sets the fraction field of aTimestampString
. 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")
yieldsTIMESTAMP '1970-01-01 02:03:04.00506'
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(TimestampString o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<TimestampString>
-
fromCalendarFields
public static TimestampString fromCalendarFields(java.util.Calendar calendar)
Creates a TimestampString from a Calendar.
-
round
public TimestampString round(int precision)
-
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()
-
-