Package org.apache.calcite.util
Class TimeString
java.lang.Object
org.apache.calcite.util.TimeString
- All Implemented Interfaces:
Comparable<TimeString>
Time literal.
Immutable, internally represented as a string (in ISO format), and can support unlimited precision (milliseconds, nanoseconds).
-
Constructor Summary
ConstructorDescriptionTimeString
(int h, int m, int s) Creates a TimeString for hour, minute, second and millisecond values.TimeString
(String v) Creates a TimeString. -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
static TimeString
fromCalendarFields
(Calendar calendar) Creates a TimeString from a Calendar.static TimeString
fromMillisOfDay
(int i) int
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 aTimeString
.withMillis
(int millis) Sets the fraction field of aTimeString
to a given number of milliseconds.withNanos
(int nanos) Sets the fraction field of aTimeString
to a given number of nanoseconds.
-
Constructor Details
-
TimeString
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
Sets the fraction field of aTimeString
to a given number of milliseconds. Nukes the value set viawithNanos(int)
.For example,
new TimeString(2, 3, 4).withMillis(56)
yieldsTIME '02:03:04.056'
.- Throws:
IllegalArgumentException
- if millis is outside the allowed range
-
withNanos
Sets the fraction field of aTimeString
to a given number of nanoseconds. Nukes the value set viawithMillis(int)
.For example,
new TimeString(2, 3, 4).withNanos(56789)
yieldsTIME '02:03:04.000056789'
.- Throws:
IllegalArgumentException
- if nanos is outside the allowed range
-
withFraction
Sets the fraction field of aTimeString
. The precision is determined by the number of leading zeros. Trailing zeros are stripped.For example,
new TimeString(2, 3, 4).withFraction("00506000")
yieldsTIME '02:03:04.00506'
. -
toString
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<TimeString>
-
fromCalendarFields
Creates a TimeString from a Calendar. -
fromMillisOfDay
-
round
-
getMillisOfDay
public int getMillisOfDay() -
toCalendar
-
toString
Converts this TimestampString to a string, truncated or padded with zeros to a given precision.
-