Interface UnitRule<T>
- Type Parameters:
T
- generic type of time context compatible toTimePoint
Represents a rule for the addition or subtraction associated with a time unit.
A unit rule will usually be registered together with an unit for a
TimeAxis
, during loading of the concrete TimePoint
-class.
For every time axis and every time unit there is exactly one rule
instance. Implementations must be always immutable.
- Author:
- Meno Hochschild
-
Method Summary
-
Method Details
-
addTo
Adds given amount to a time point in the context of an associated time unit.
This method is called by the
plus()
- andminus()
-methods in the classTimePoint
. If not specified otherwise then a possible range overflow will be resolved such that the last valid time point is choosen. For example the addition of one month to date of 31th of may will yield June, 30th.- Parameters:
timepoint
- time pointamount
- count of units to be added to- Returns:
- result of addition as changed copy, given time point remains unaffected
- Throws:
IllegalArgumentException
- if boundary constraints are violatedArithmeticException
- in case of numerical overflow- See Also:
TimePoint.plus(long, U)
,TimePoint.minus(long, U)
-
between
Queries how many units are between given time points.
This method is called by
TimePoint.until(T, U)
. The expressionstart.until(end, unit)
corresponds toruleForUnit.between(start, end)
. Only full units will be counted. A possible remainder of subtraction will always be truncated.- Parameters:
start
- start time pointend
- end time point- Returns:
- difference in units (negative if
end
is beforestart
) - Throws:
ArithmeticException
- in case of numerical overflow- See Also:
TimePoint.until(T, U)
-