Class DurationFormatter
- java.lang.Object
-
- com.pervasivecode.utils.time.DurationFormatter
-
public final class DurationFormatter extends Object
Formatter for aDuration
value.Duration
s are split into avaialbleChronoUnit
s as specified in theDurationFormat
, using unitDuration
s obtained fromChronoUnit
values.The format is specified by a
DurationFormat
, allowing formats such as:- 1s 370ms
- 1.37s
- 2w 3d
- 4w1d4h22m
- 6 weeks, 4 days, 23 hours
- -1m 30s
Zero
Duration
s are always formatted with the unit specified inunitForZeroDuration
.Unit suffix strings are obtained from a
UnitSuffixProvider
, which has access to the unit and the actual value being rendered, for the sake of maximum flexibility.UnitSuffixProviders
has factory methods for more typical cases such as one suffix per unit, or one singular and one plural suffix per unit.Negative
Duration
values are split so that only the first part of the formatted value is formatted as a negative number; the smaller parts are formatted as positive numbers. See the example above: -90 seconds is formatted as -1 minutes, 30 seconds (not -1 minutes, -30 seconds).Note:
Duration
values are defined in terms of seconds and nanoseconds. Since calendars' day, month, and year lengths vary over time, this class uses theChronoUnit.MONTHS
andChronoUnit.YEARS
unit values that are approximations of actual calendar months and years.
-
-
Constructor Summary
Constructors Constructor Description DurationFormatter(DurationFormat format)
Create a DurationFormatter.
-
-
-
Constructor Detail
-
DurationFormatter
public DurationFormatter(DurationFormat format)
Create a DurationFormatter.- Parameters:
format
- The formatting rules to use.
-
-