Package ai.dat.core.configuration.time
Class TimeUtils
java.lang.Object
ai.dat.core.configuration.time.TimeUtils
Collection of utilities about time intervals.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatWithHighestUnit(Duration duration) Pretty prints the duration as a lowest granularity unit that does not lose precision.static StringgetStringInMillis(Duration duration) static DurationparseDuration(String text) Parse the given string to a javaDuration.static DurationtoDuration(Time time)
-
Constructor Details
-
TimeUtils
public TimeUtils()
-
-
Method Details
-
parseDuration
Parse the given string to a javaDuration. The string is in format "{length value}{time unit label}", e.g. "123ms", "321 s". If no time unit label is specified, it will be considered as milliseconds.Supported time unit labels are:
- DAYS: "d", "day"
- HOURS: "h", "hour"
- MINUTES: "m", "min", "minute"
- SECONDS: "s", "sec", "second"
- MILLISECONDS: "ms", "milli", "millisecond"
- MICROSECONDS: "µs", "micro", "microsecond"
- NANOSECONDS: "ns", "nano", "nanosecond"
- Parameters:
text- string to parse.
-
getStringInMillis
- Parameters:
duration- to convert to string- Returns:
- duration string in millis
-
formatWithHighestUnit
Pretty prints the duration as a lowest granularity unit that does not lose precision.Examples:
NOTE: It supports only durations that fit into long.Duration.ofMilliseconds(60000) will be printed as 1 min Duration.ofHours(1).plusSeconds(1) will be printed as 3601 s -
toDuration
- Parameters:
time- time to transform into duration- Returns:
- duration equal to the given time
-