Class Duration

java.lang.Object
org.miaixz.bus.gitlab.models.Duration
All Implemented Interfaces:
Serializable

public class Duration extends Object implements Serializable
This class represents a duration in time.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Duration(int seconds)
    Create a Duration instance from a number of seconds.
    Duration(String durationString)
    Create a Duration instance from a human readable string.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Duration
     
    int
    Get the number of seconds this duration represents.
    static final int
    parse(String durationString)
    Parses a human readable duration string and calculates the number of seconds it represents.
    void
    setSeconds(int seconds)
    Set the number of seconds this duration represents.
     
    static final String
    toString(int durationSeconds)
    Create a human readable duration string from seconds.
    static final String
    toString(int durationSeconds, boolean includeMonths)
    Create a human readable duration string from seconds.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Duration

      public Duration(String durationString)
      Create a Duration instance from a human readable string. e.g: 3h30m
      Parameters:
      durationString - a duration in human readable format
    • Duration

      public Duration(int seconds)
      Create a Duration instance from a number of seconds.
      Parameters:
      seconds - the number of seconds for this Duration instance to represent
  • Method Details

    • toString

      public static final String toString(int durationSeconds)
      Create a human readable duration string from seconds.
      Parameters:
      durationSeconds - the total number of seconds in the duration
      Returns:
      a human readable string representing the duration
    • toString

      public static final String toString(int durationSeconds, boolean includeMonths)
      Create a human readable duration string from seconds.
      Parameters:
      durationSeconds - the total number of seconds in the duration
      includeMonths - when true will include months "mo", in the string otherwise uses "4w" for each month
      Returns:
      a human readable string representing the duration
    • parse

      public static final int parse(String durationString)
      Parses a human readable duration string and calculates the number of seconds it represents.
      Parameters:
      durationString - the human readable duration
      Returns:
      the total number of seconds in the duration
    • getSeconds

      public int getSeconds()
      Get the number of seconds this duration represents.
      Returns:
      the number of seconds this duration represents
    • setSeconds

      public void setSeconds(int seconds)
      Set the number of seconds this duration represents.
      Parameters:
      seconds - the number of seconds this duration represents
    • toString

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

      public static Duration forValue(String value)