Package com.storedobject.core
Class TimeDuration
java.lang.Object
com.storedobject.core.Quantity
com.storedobject.core.TimeDuration
- All Implemented Interfaces:
Storable,Comparable<Quantity>
Represents a duration of time as a quantity.
This class provides functionality to perform arithmetic operations
and format time durations in various string representations.
It supports units such as seconds, minutes, hours, and days.
- Author:
- Syam
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MeasurementUnitThe default unit of time measurement used in theTimeDurationclass. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for the TimeDuration class.TimeDuration(double value, MeasurementUnit unit) Constructs a TimeDuration instance with the specified value and measurement unit.TimeDuration(double value, String unit) Constructs a TimeDuration instance with the specified value and unit.TimeDuration(double value, TimeUnit unit) Constructs a TimeDuration instance with the specified numeric value and time unit.TimeDuration(BigDecimal value, MeasurementUnit unit) Constructs a TimeDuration instance with the specified value and measurement unit.TimeDuration(BigDecimal value, String unit) Constructs a TimeDuration instance using the specified value and unit.TimeDuration(BigDecimal value, TimeUnit unit) Constructs a TimeDuration instance with the specified value and time unit. -
Method Summary
Modifier and TypeMethodDescriptionabsolute()Absolute value of this quantity.Add quantityAdd quantity valueadd(BigDecimal quantity) Add quantitydivide(double divisor) Divide the quantity with a valuedivide(BigDecimal divisor) Divide the quantity with a valueformat()Format the duration as a string of the form "D days HH:MM:SS".format(boolean allowDays) Format the duration as a string of the form "D days HH:MM:SS" or "HH:MM:SS".format(boolean allowDays, boolean stripSeconds) Format the duration as a string of the form "D days HH:MM:SS" or "HH:MM:SS".multiply(double multiplicand) Multiplymultiply(BigDecimal multiplicand) Multiplynegate()Reverses the sign of this quantitySubtract quantitySubtract quantitysubtract(BigDecimal quantity) Subtract quantitytoString()Create the formatted representation of the quantity value with appropriate decimals places.zero()Create a quantity of these types with zero value.Methods inherited from class com.storedobject.core.Quantity
canConvert, canConvert, canConvert, canConvert, compareTo, convert, convert, convert, convert, convertValue, create, create, create, create, create, create, create, create, create, create, create, create, divide, equals, equalsWhenZero, getClass, getStorableValue, getType, getTypeName, getUnit, getUnit, getUnit, getValue, hashCode, isCompatible, isConvertible, isConvertible, isGreaterThan, isGreaterThan, isGreaterThanOrEqual, isGreaterThanOrEqual, isLessThan, isLessThan, isLessThanOrEqual, isLessThanOrEqual, isNegative, isPositive, isZero, multiply, percentageOf, quantityTypes, round, setUnit, setUnit, sum, toString, toString, toString, types
-
Field Details
-
defaultUnit
The default unit of time measurement used in theTimeDurationclass. It represents the base unit "second" with a scale factor of 1. This unit is used as a standard reference for converting and performing operations on various time durations within the class.
-
-
Constructor Details
-
TimeDuration
public TimeDuration()Default constructor for the TimeDuration class. It initializes a TimeDuration object with a value of zero and the default time unit. -
TimeDuration
Constructs a TimeDuration instance with the specified value and unit.- Parameters:
value- The numeric value of the time duration to be represented.unit- The string representation of the time unit (e.g., "seconds", "minutes", "hours").
-
TimeDuration
Constructs a TimeDuration instance with the specified value and measurement unit.- Parameters:
value- The numeric value representing the time duration.unit- The measurement unit for the time duration (e.g., "seconds", "minutes", "hours").
-
TimeDuration
Constructs a TimeDuration instance using the specified value and unit.- Parameters:
value- The numeric value of the time duration to be represented as a BigDecimal.unit- The string representation of the time unit (e.g., "seconds", "minutes", "hours").
-
TimeDuration
Constructs a TimeDuration instance with the specified value and measurement unit.- Parameters:
value- The numeric value representing the time duration, provided as a BigDecimal.unit- The measurement unit for the time duration, represented as a MeasurementUnit object.
-
TimeDuration
Constructs a TimeDuration instance with the specified numeric value and time unit.- Parameters:
value- The numeric value representing the time duration.unit- The time unit for the duration (e.g., TimeUnit.SECONDS, TimeUnit.MINUTES).
-
TimeDuration
Constructs a TimeDuration instance with the specified value and time unit.- Parameters:
value- The numeric value representing the time duration, provided as a BigDecimal.unit- The time unit for the duration (e.g., TimeUnit.SECONDS, TimeUnit.MINUTES).
-
-
Method Details
-
zero
Create a quantity of these types with zero value. -
add
Add quantity value -
add
Add quantity -
add
Add quantity -
subtract
Subtract quantity -
subtract
Subtract quantity -
subtract
Subtract quantity -
multiply
Multiply -
multiply
Multiply -
divide
Divide the quantity with a value -
divide
Divide the quantity with a value -
negate
Reverses the sign of this quantity -
absolute
Absolute value of this quantity. -
toString
-
format
Format the duration as a string of the form "D days HH:MM:SS".- Returns:
- Formatted string
-
format
Format the duration as a string of the form "D days HH:MM:SS" or "HH:MM:SS".- Parameters:
allowDays- Allow days?- Returns:
- Formatted string
-
format
Format the duration as a string of the form "D days HH:MM:SS" or "HH:MM:SS".- Parameters:
allowDays- Allow days?stripSeconds- Strip seconds?- Returns:
- Formatted string
-