Package com.linkedin.alpini.base.misc
Enum Class TimeFormat
- All Implemented Interfaces:
Serializable
,Comparable<TimeFormat>
,Constable
This utility class provides methods to format and parse a timespan in a human readable form. The timespan is formatted broken down in days,
hours, minutes, seconds, and milliseconds. The time span 5 minutes and 23 seconds is displayed simply as "5m23s" instead of the millisecond value
"323000". A larger value might be displayed as "3d17h27m33s15ms".
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatDatetime
(long datetime) Format the given date in a human readable form.static String
formatDatetime
(Date date) Format the given date in a human readable form.static String
formatTimespan
(long millis) Format the given number of milliseconds in a more human readable form.static void
formatTimespan
(long millis, StringBuilder sb) Format the given number of milliseconds in a more human readable form and append it to the given StringBuilder.static Date
Parse the given String date and time to a millisecond value.static long
Parse the given String date and time to a millisecond value.static long
Parse the given String timespan to a millisecond value.static TimeFormat
Returns the enum constant of this class with the specified name.static TimeFormat[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
SINGLETON
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
parseDatetimeToMillis
Parse the given String date and time to a millisecond value. The string must be in the form returned byformatDatetime(long)
orformatDatetime(Date)
.- Parameters:
s
- date time to parse - like "2012/04/05 14:38:03.311"- Returns:
- the date and time, in milliseconds
- Throws:
IllegalArgumentException
- if s is invalid
-
parseDatetimeToDate
Parse the given String date and time to a millisecond value. The string must be in the form returned byformatDatetime(long)
orformatDatetime(Date)
.- Parameters:
s
- date time to parse - like "2012/04/05 14:38:03.311"- Returns:
- the date and time
- Throws:
IllegalArgumentException
- if s is invalid
-
formatDatetime
Format the given date in a human readable form.- Parameters:
date
- the date- Returns:
- a human readable date, such as "2012/04/05 14:38:03.311".
-
formatDatetime
Format the given date in a human readable form.- Parameters:
datetime
- the date and time, in milliseconds- Returns:
- a human readable date, such as "2012/04/05 14:38:03.311".
-
parseTimespanToMillis
Parse the given String timespan to a millisecond value. The string must be in the form returned byformatTimespan(long)
. In particular, zero time should be represented as "0ms", not as "0" or "".- Parameters:
s
- timespan to parse - like 3d17h27m33s15ms- Returns:
- the number of milliseconds
- Throws:
IllegalArgumentException
- if the timespan is invalid
-
formatTimespan
Format the given number of milliseconds in a more human readable form.- Parameters:
millis
- number of milliseconds- Returns:
- a human readable duration, such as "3d17h27m33s15ms".
-
formatTimespan
Format the given number of milliseconds in a more human readable form and append it to the given StringBuilder.- Parameters:
millis
- number of millisecondssb
- append the formatted timestamp here
-