Package org.apache.pinot.spi.utils
Class TimeUtils
- java.lang.Object
-
- org.apache.pinot.spi.utils.TimeUtils
-
public class TimeUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static longVALID_MAX_TIME_MILLISstatic longVALID_MIN_TIME_MILLISstatic org.joda.time.IntervalVALID_TIME_INTERVAL
-
Method Summary
Modifier and Type Method Description static StringconvertMillisToPeriod(Long millis)Converts milliseconds into human readable duration string.static LongconvertPeriodToMillis(String timeStr)Converts a string representing a period/duration to corresponding milliseconds.static LongconvertTimestampToMillis(String timeStr)Converts a string representing the timestamp to corresponding milliseconds.static longgetValidMaxTimeMillis()Returns the maximum valid time in milliseconds.static longgetValidMinTimeMillis()Returns the minimum valid time in milliseconds.static booleanisPeriodValid(String timeStr)Checks if the given period string is valid i.e.static booleanisTimestampValid(String timeStr)Checks if the given timestamp string is validstatic booleanisValidTimeInterval(org.joda.time.Interval timeInterval)Given a time interval, returns true if the interval is between a valid range, false otherwise.static TimeUnittimeUnitFromString(String timeUnitString)Converts a time unit string intoTimeUnit, ignoring case.static booleantimeValueInValidRange(long timeValueInMillis)Given a time value, returns true if the value is between a valid range, false otherwise.
-
-
-
Method Detail
-
timeUnitFromString
@Nullable public static TimeUnit timeUnitFromString(@Nullable String timeUnitString)
Converts a time unit string intoTimeUnit, ignoring case. Fornullor empty time unit string, returnsnull.Besides the standard time unit, also support the following time unit strings:
- "daysSinceEpoch" -> DAYS
- "hoursSinceEpoch" -> HOURS
- "minutesSinceEpoch" -> MINUTES
- "secondsSinceEpoch" -> SECONDS
- "millisSinceEpoch"/"millisecondsSinceEpoch" -> MILLISECONDS
- "microsSinceEpoch"/"microsecondsSinceEpoch" -> MICROSECONDS
- "nanosSinceEpoch"/"nanosecondsSinceEpoch" -> NANOSECONDS
- Parameters:
timeUnitString- The time unit string to convert, e.g. "DAYS" or "SECONDS"- Returns:
- The corresponding
TimeUnit
-
timeValueInValidRange
public static boolean timeValueInValidRange(long timeValueInMillis)
Given a time value, returns true if the value is between a valid range, false otherwise.The current valid range used is between beginning of 1971 and beginning of 2071.
-
isValidTimeInterval
public static boolean isValidTimeInterval(org.joda.time.Interval timeInterval)
Given a time interval, returns true if the interval is between a valid range, false otherwise.The current valid range used is between beginning of 1971 and beginning of 2071.
-
getValidMinTimeMillis
public static long getValidMinTimeMillis()
Returns the minimum valid time in milliseconds.
-
getValidMaxTimeMillis
public static long getValidMaxTimeMillis()
Returns the maximum valid time in milliseconds.
-
convertPeriodToMillis
public static Long convertPeriodToMillis(String timeStr)
Converts a string representing a period/duration to corresponding milliseconds. For ex, input "1d" would return 86400000L. Supported units are days (d), hours (h), minutes (m) and seconds (s).- Parameters:
timeStr- string representing the duration- Returns:
- the corresponding time converted to milliseconds
- Throws:
IllegalArgumentException- if the string does not conform to the expected format
-
convertTimestampToMillis
public static Long convertTimestampToMillis(String timeStr)
Converts a string representing the timestamp to corresponding milliseconds.- Parameters:
timeStr- string representing the timestamp in ISO 8601 format- Returns:
- the corresponding time converted to milliseconds
- Throws:
IllegalArgumentException- if the string does not conform to the expected format
-
convertMillisToPeriod
public static String convertMillisToPeriod(Long millis)
Converts milliseconds into human readable duration string. For ex, input of 86400000L would return "1d".- Parameters:
millis- the value in milliseconds to be converted- Returns:
- the corresponding human readable string or empty string if value cannot be converted
-
isPeriodValid
public static boolean isPeriodValid(String timeStr)
Checks if the given period string is valid i.e. has format like 30h, 15d, 10m
-
isTimestampValid
public static boolean isTimestampValid(String timeStr)
Checks if the given timestamp string is valid
-
-