Enum Class TimeFormat

java.lang.Object
java.lang.Enum<TimeFormat>
com.linkedin.alpini.base.misc.TimeFormat
All Implemented Interfaces:
Serializable, Comparable<TimeFormat>, Constable

public enum TimeFormat extends Enum<TimeFormat>
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".
  • Enum Constant Details

    • SINGLETON

      public static final TimeFormat SINGLETON
  • Method Details

    • values

      public static TimeFormat[] 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

      public static TimeFormat valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • parseDatetimeToMillis

      public static long parseDatetimeToMillis(String s) throws IllegalArgumentException
      Parse the given String date and time to a millisecond value. The string must be in the form returned by formatDatetime(long) or formatDatetime(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

      public static Date parseDatetimeToDate(String s) throws IllegalArgumentException
      Parse the given String date and time to a millisecond value. The string must be in the form returned by formatDatetime(long) or formatDatetime(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

      public static String formatDatetime(Date date)
      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

      public static String formatDatetime(long datetime)
      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

      public static long parseTimespanToMillis(String s) throws IllegalArgumentException
      Parse the given String timespan to a millisecond value. The string must be in the form returned by formatTimespan(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

      public static String formatTimespan(long millis)
      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

      public 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.
      Parameters:
      millis - number of milliseconds
      sb - append the formatted timestamp here