- All Implemented Interfaces:
Serializable,Comparable<Time>,Constable,Dimension,DimensionWithLinearConversion
The various instances of time periods …
The instance of Time refers to the respective instances of
TimeUnit
and
ChronoUnit
wherever possible.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: Time.java 1073 2023-10-01 11:08:51Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.value.Time"
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classAn implementation ofTemporalUnit, based on the settings for theTimeinstance.Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionA bank month.A bank year.A century.A day.A decade.A fortnight (2 weeks or 14 days).Half a day.An hour.A microsecond.A millisecond.A minute.A month.A nanosecond.A second.A year.A week (7 days).A tropical year, according to SI. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BigDecimalThe factor.private final Optional<TemporalUnit> The time unit as used by thejava.timepackage.private final TimeUnitThe time unit as used by thejava.util.concurrentpackage.private final StringThe unit symbol.Fields inherited from interface org.tquadrat.foundation.value.api.DimensionWithLinearConversion
MSG_UnknownUnit -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateTime(BigDecimal factor, String unitSymbol, TimeUnit timeUnit, TemporalUnit temporalUnit) Creates a newTimeinstance. -
Method Summary
Modifier and TypeMethodDescriptionprotected TemporalUnitReturns this instance ofTimeas an instance ofTemporalUnit.final TimebaseUnit()Returns the base unit.final BigDecimalfactor()Returns the factor that is used to convert a value from this unit to the base unit.static final TimeReturns theTimeinstance for the given unit.static final TimeforUnit(ChronoUnit unit) Returns theTimeinstance for the given instance ofChronoUnit.static final TimeforUnit(TemporalUnit unit) Returns theTimeinstance for the given instance ofTemporalUnit.static final TimeReturns theTimeinstance for the given instance ofTimeUnit.final TemporalUnitReturns the correspondentTemporalUnitfor this instance, as used by thejava.timepackage.final TimeUnitReturns the correspondentTimeUnitfor this instance, as used by thejava.util.concurrentpackage.final StringReturns the unit symbol for the dimension as a single line string.static TimeReturns the enum constant of this class with the specified name.static Time[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods inherited from interface org.tquadrat.foundation.value.api.Dimension
equals, getPrecision, name, toString, unitSymbolForPrintingMethods inherited from interface org.tquadrat.foundation.value.api.DimensionWithLinearConversion
fromBase, toBase
-
Enum Constant Details
-
NANOSECOND
A nanosecond. -
MICROSECOND
A microsecond. -
MILLISECOND
A millisecond. -
SECOND
A second. -
MINUTE
A minute. -
HOUR
An hour. -
HALF_DAY
Half a day. -
DAY
A day. -
WEEK
A week (7 days). -
FORTNIGHT
A fortnight (2 weeks or 14 days). -
BANK_MONTH
A bank month.
This has a fixed length of exact 30 days.
-
MONTH
A month.
This is the average month, calculated using the average year with 365.2425 days divided by 12.
-
BANK_YEAR
A bank year.
This has a fixed length of exact 360 days.
-
YEAR
A tropical year, according to SI.- See Also:
-
SIMPLE_YEAR
A year.
This is calculated as the average year with 365.2425 days.
- See Also:
-
DECADE
A decade.
This is calculated as ten average years with 365.2425 days each.
- See Also:
-
CENTURY
A century.
This is calculated as one hundred average years with 365.2425 days each.
- See Also:
-
-
Field Details
-
m_Factor
The factor. -
m_UnitSymbol
The unit symbol. -
m_TemporalUnit
The time unit as used by thejava.timepackage. -
m_TimeUnit
The time unit as used by thejava.util.concurrentpackage.
-
-
Constructor Details
-
Time
Creates a newTimeinstance.- Parameters:
factor- The factor.unitSymbol- The unit symbol.timeUnit- The time unit as for thejava.util.concurrentpackage; may benull.temporalUnit- The time unit as for thejava.timepackage; may benull.
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
asTemporalUnit
Returns this instance ofTimeas an instance ofTemporalUnit.- Returns:
thisasTemporalUnit.
-
baseUnit
Returns the base unit.
E.g. for length, the base unit would be Meter (m), for mass, it is Kilogram (kg), and so on.
-
factor
Returns the factor that is used to convert a value from this unit to the base unit.
For length, if you have to convert a Centimeter value to Meter, you will divide that by 100 or multiply it with a factor of 0.01.
For the base unit, the factor is 1.0.
- Specified by:
factorin interfaceDimensionWithLinearConversion- Returns:
- The factor.
- See Also:
-
forUnit
Returns theTimeinstance for the given instance ofChronoUnit.- Parameters:
unit- The unit.- Returns:
- The respective instance.
- Throws:
IllegalArgumentException- The given unit is unknown.
-
forUnit
Returns theTimeinstance for the given instance ofTemporalUnit.- Parameters:
unit- The unit.- Returns:
- The respective instance.
- Throws:
IllegalArgumentException- The given unit is unknown.
-
forUnit
Returns theTimeinstance for the given instance ofTimeUnit.- Parameters:
unit- The unit.- Returns:
- The respective instance.
- Throws:
IllegalArgumentException- The given unit is unknown.
-
forUnit
Returns theTimeinstance for the given unit.- Parameters:
unitSymbol- The unit symbol.- Returns:
- The respective instance.
- Throws:
IllegalArgumentException- The given unit is unknown.
-
getTemporalUnit
Returns the correspondentTemporalUnitfor this instance, as used by thejava.timepackage. Because we define here more units as in that package, the return value may benull.- Returns:
- The corresponding temporal unit instance, or
nullif there is no corresponding time unit.
-
getTimeUnit
Returns the correspondentTimeUnitfor this instance, as used by thejava.util.concurrentpackage. Because we define here more units as in that package, the return value may benull.- Returns:
- The corresponding time unit instance, or
nullif there is no corresponding time unit.
-
unitSymbol
Returns the unit symbol for the dimension as a single line string.
For a length, this would be "m", for a speed "km/h", and for an acceleration, it could be "m/(s^2)".
- Specified by:
unitSymbolin interfaceDimension- Returns:
- The unit.
-
