Class Time

java.lang.Object
com.marcpg.libpg.data.time.Time

public class Time extends Object
Time is used to convert and store times with different Time.Units, etc.
Since:
0.0.1
  • Constructor Details

    • Time

      public Time(long seconds)
      Create a new Time object.
      Parameters:
      seconds - The time in seconds.
    • Time

      public Time(@NotNull @NotNull Time time)
      Clones a Time object.
      Parameters:
      time - The time to clone.
    • Time

      public Time(long time, @NotNull @NotNull Time.Unit unit)
      Create a new Time object.
      Parameters:
      time - The time value.
      unit - The unit of the time value.
  • Method Details

    • getOneUnitFormatted

      public String getOneUnitFormatted()
      Get the time as a formatted string that is readable. The formatted time uses the highest Time.Unit possible for the best readability.
      Returns:
      The time as a formatted string.
      See Also:
    • getPreciselyFormatted

      public String getPreciselyFormatted()
      Get the time as a formatted string that is readable. The formatted time uses the highest Time.Unit possible and then lower ones for remaining time.
      Returns:
      The time as a formatted string.
      See Also:
    • get

      public long get()
      Get the time in the default seconds format.
      Returns:
      The time in seconds.
      Since:
      0.0.2
    • getAs

      public long getAs(@NotNull @NotNull Time.Unit unit)
      Get the time in a specific unit.
      Parameters:
      unit - The unit in which the time should be converted.
      Returns:
      The converted time.
    • getAsExact

      public double getAsExact(@NotNull @NotNull Time.Unit unit)
      Get the time in a specific unit as a double for exact precision.
      Parameters:
      unit - The unit in which the time should be converted.
      Returns:
      The converted time.
    • increment

      public void increment(long time, @NotNull @NotNull Time.Unit unit)
      Increment the time, useful if used in timers.
      Parameters:
      time - The time in the unit of the second parameter.
      unit - The unit of the time.
    • increment

      public void increment(long seconds)
      Increment the time, useful if used in timers.
      Parameters:
      seconds - The time in seconds.
    • increment

      public void increment()
      Increment the time, useful if used in timers.
      This increments the time by 1 second.
    • decrement

      public void decrement(long time, @NotNull @NotNull Time.Unit unit)
      Decrement the time, useful if used in timers/countdowns.
      Parameters:
      time - The time in the unit of the second parameter.
      unit - The unit of the time.
    • decrement

      public void decrement(long seconds)
      Decrement the time, useful if used in timers/countdowns.
      Parameters:
      seconds - The time in seconds
    • decrement

      public void decrement()
      Decrement the time, useful if used in timers/countdowns.
      This decrements the time by 1 second.
    • setAllowNegatives

      public void setAllowNegatives(boolean allowNegatives)
      Changes whether the time allows negative values or not.
      Parameters:
      allowNegatives - If the time allows negative values.
      Since:
      0.0.4
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • oneUnitFormat

      @NotNull public static @NotNull String oneUnitFormat(long s)
      Format the time as a string representation using the highest possible unit.
      Parameters:
      s - The time in seconds.
      Returns:
      The formatted time string.
    • oneUnitFormat

      @NotNull public static @NotNull String oneUnitFormat(@NotNull @NotNull Time time)
      Format the time as a string representation using the highest possible unit.
      Parameters:
      time - The time.
      Returns:
      The formatted time string.
    • preciselyFormat

      @NotNull public static @NotNull String preciselyFormat(long s)
      Format the time as a string representation using the highest possible unit and then lower ones for remaining time.
      Parameters:
      s - The time in seconds.
      Returns:
      The formatted time string.
    • preciselyFormat

      @NotNull public static @NotNull String preciselyFormat(@NotNull @NotNull Time time)
      Format the time as a string representation using the highest possible unit and then lower ones for remaining time.
      Parameters:
      time - The time.
      Returns:
      The formatted time string.
    • parse

      @NotNull public static @NotNull Time parse(String input)
      Parse the input string to a time. Useful for parsing text user input to a time object.
      Parameters:
      input - String to parse, must follow the scheme: [time/int]+[abbreviation], so for example "1min", "3d", etc. Only one single unit is expected!
      Returns:
      The parsed time.
      Since:
      0.0.3