Package org.apache.calcite.util
Class TimestampString
java.lang.Object
org.apache.calcite.util.TimestampString
- All Implemented Interfaces:
Comparable<TimestampString>
Timestamp literal.
Immutable, internally represented as a string (in ISO format), and can support unlimited precision (milliseconds, nanoseconds).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTimestampString
(int year, int month, int day, int h, int m, int s) Creates a TimestampString for year, month, day, hour, minute, second, millisecond values.Creates a TimeString. -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
static TimestampString
fromCalendarFields
(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.long
Returns the number of milliseconds since the epoch.int
hashCode()
round
(int precision) toString()
toString
(int precision) Converts this TimestampString to a string, truncated or padded with zeros to a given precision.withFraction
(String fraction) Sets the fraction field of aTimestampString
.withMillis
(int millis) Sets the fraction field of aTimestampString
to a given number of milliseconds.withNanos
(int nanos) Sets the fraction field of aTimestampString
to a given number of nanoseconds.
-
Field Details
-
EPOCH
The Unix epoch.
-
-
Constructor Details
-
TimestampString
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 Details
-
withMillis
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
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
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
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<TimestampString>
-
fromCalendarFields
Creates a TimestampString from a Calendar. -
round
-
getMillisSinceEpoch
public long getMillisSinceEpoch()Returns the number of milliseconds since the epoch. -
fromMillisSinceEpoch
Creates a TimestampString that is a given number of milliseconds since the epoch. -
toCalendar
-
toString
Converts this TimestampString to a string, truncated or padded with zeros to a given precision.
-