Enum Class DurationFormat

java.lang.Object
java.lang.Enum<DurationFormat>
com.complexible.common.timer.DurationFormat
All Implemented Interfaces:
Serializable, Comparable<DurationFormat>, Constable

public enum DurationFormat extends Enum<DurationFormat>

A simple class to provide various formatting options for durations represented in milliseconds. The durations are displayed in terms of hours, minutes, seconds, and milliseconds.

Since:
2.0
Version:
2.0
Author:
Evren Sirin
  • Enum Constant Details

    • FULL

      public static final DurationFormat FULL
      Format duration in full format. Example: 0 hour(s) 2 minute(s) 13 second(s) 572 milliseconds(s)
    • LONG

      public static final DurationFormat LONG
      Format duration in long format. Example: 00:02:13.572
    • MEDIUM

      public static final DurationFormat MEDIUM
      Format duration in medium format (no milliseconds). Example: 00:02:13
    • SHORT

      public static final DurationFormat SHORT
      Format duration in short format (no hours or milliseconds). Example: 00:02
  • Method Details

    • values

      public static DurationFormat[] 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 DurationFormat 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
    • format

      public String format(long durationInMilliseconds)
      Format the given duration in milliseconds according to the style defined by this DurationFormat class.
      Parameters:
      durationInMilliseconds - duration represented in milliseconds
      Returns:
      duration formatted as a string