Class Time

All Implemented Interfaces:
Serializable

public class Time extends Measurement<TimeUnit>
Contains a time value and unit.
See Also:
  • Constructor Details

    • Time

      public Time(Number value, TimeUnit unit)
      Constructor with value and unit.
      Parameters:
      value - time value.
      unit - unit of distance.
      Throws:
      IllegalArgumentException - if either value or unit is null.
    • Time

      Time()
      Constructor.
  • Method Details

    • equals

      public boolean equals(Measurement<TimeUnit> other, double tolerance)
      Determines if two time instances are equal up to a certain tolerance. If needed, this method attempts unit conversion to compare both objects.
      Overrides:
      equals in class Measurement<TimeUnit>
      Parameters:
      other - another time to compare.
      tolerance - amount of tolerance to determine whether two time instances are equal or not.
      Returns:
      true if provided time is assumed to be equal to this instance, false otherwise.
    • add

      public static double add(double value1, TimeUnit unit1, double value2, TimeUnit unit2, TimeUnit resultUnit)
      Adds two time values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of addition.
    • add

      public static Number add(Number value1, TimeUnit unit1, Number value2, TimeUnit unit2, TimeUnit resultUnit)
      Adds two time values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of addition.
    • add

      public static void add(Time arg1, Time arg2, Time result)
      Adds two time instances and stores the result into provided instance.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      result - instance where result will be stored.
    • addAndReturnNew

      public static Time addAndReturnNew(Time arg1, Time arg2, TimeUnit unit)
      Adds two time instances.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      unit - unit of returned time.
      Returns:
      a new instance containing result.
    • addAndReturnNew

      public Time addAndReturnNew(double value, TimeUnit unit, TimeUnit resultUnit)
      Adds provided time value and unit and returns a new time instance using provided unit.
      Parameters:
      value - value to be added.
      unit - unit of value to be added.
      resultUnit - unit of returned time.
      Returns:
      a new time containing result.
    • addAndReturnNew

      public Time addAndReturnNew(Number value, TimeUnit unit, TimeUnit resultUnit)
      Adds provided time value and unit and returns a new time instance using provided unit.
      Parameters:
      value - value to be added.
      unit - unit of value to be added.
      resultUnit - unit of returned time.
      Returns:
      a new time containing result.
    • addAndReturnNew

      public Time addAndReturnNew(Time t, TimeUnit unit)
      Adds provided time to current instance and returns a new time instance.
      Parameters:
      t - time to be added.
      unit - unit of returned time.
      Returns:
      a new time containing result.
    • add

      public void add(double value, TimeUnit unit)
      Adds provided time value and unit and updates current time instance.
      Parameters:
      value - time value to be added.
      unit - unit of time value.
    • add

      public void add(Number value, TimeUnit unit)
      Adds provided time value and unit and updates current time instance.
      Parameters:
      value - time value to be added.
      unit - unit of time value.
    • add

      public void add(Time time)
      Adds provided time and updates current time instance.
      Parameters:
      time - time to be added.
    • add

      public void add(Time t, Time result)
      Adds provided time and stores the result into provided time instance.
      Parameters:
      t - time to be added.
      result - instance where result will be stored.
    • subtract

      public static double subtract(double value1, TimeUnit unit1, double value2, TimeUnit unit2, TimeUnit resultUnit)
      Subtracts two time values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of subtraction.
    • subtract

      public static Number subtract(Number value1, TimeUnit unit1, Number value2, TimeUnit unit2, TimeUnit resultUnit)
      Subtracts two time values and units and returns the result.
      Parameters:
      value1 - 1st argument value.
      unit1 - 1st argument unit.
      value2 - 2nd argument value.
      unit2 - 2nd argument unit.
      resultUnit - unit of result to be returned.
      Returns:
      result of subtraction.
    • subtract

      public static void subtract(Time arg1, Time arg2, Time result)
      Subtracts two time instances and stores the result into provided instance.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      result - instance where result will be stored.
    • subtractAndReturnNew

      public static Time subtractAndReturnNew(Time arg1, Time arg2, TimeUnit unit)
      Subtracts two time instances.
      Parameters:
      arg1 - 1st argument.
      arg2 - 2nd argument.
      unit - unit of returned time.
      Returns:
      a new instance containing result.
    • subtractAndReturnNew

      public Time subtractAndReturnNew(double value, TimeUnit unit, TimeUnit resultUnit)
      Subtracts provided time value and unit and returns a new time instance using provided unit.
      Parameters:
      value - value to be subtracted.
      unit - unit of value to be subtracted.
      resultUnit - unit of returned time.
      Returns:
      a new time containing result.
    • subtractAndReturnNew

      public Time subtractAndReturnNew(Number value, TimeUnit unit, TimeUnit resultUnit)
      Subtracts provided time value and unit and returns a new time instance using provided unit.
      Parameters:
      value - value to be subtracted.
      unit - unit of value to be subtracted.
      resultUnit - unit of returned time.
      Returns:
      a new time containing result.
    • subtractAndReturnNew

      public Time subtractAndReturnNew(Time t, TimeUnit unit)
      Subtracts provided time to current instance and returns a new instance.
      Parameters:
      t - time to be subtracted.
      unit - unit of returned time.
      Returns:
      a new time containing result.
    • subtract

      public void subtract(double value, TimeUnit unit)
      Subtracts provided time value and unit and updates current time instance.
      Parameters:
      value - time value to be subtracted.
      unit - unit of time value.
    • subtract

      public void subtract(Number value, TimeUnit unit)
      Subtracts provided time value and unit and updates current time instance.
      Parameters:
      value - time value to be subtracted.
      unit - unit of time value.
    • subtract

      public void subtract(Time time)
      Subtract provided time and updates current time.
      Parameters:
      time - time to be subtracted.
    • subtract

      public void subtract(Time t, Time result)
      Subtracts provided time and stores the result into provided time.
      Parameters:
      t - time to be subtracted.
      result - instance where result will be stored.