Package com.ibm.icu.impl.duration
Class BasicDurationFormatter
java.lang.Object
com.ibm.icu.impl.duration.BasicDurationFormatter
- All Implemented Interfaces:
DurationFormatter
Core implementation class for DurationFormatter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PeriodBuilder
private DateFormatter
private long
private PeriodFormatter
private String
private TimeZone
-
Constructor Summary
ConstructorsModifierConstructorDescriptionBasicDurationFormatter
(PeriodFormatter formatter, PeriodBuilder builder, DateFormatter fallback, long fallbackLimit) Creates a basic duration formatter with the given formatter, builder, and fallback.protected
BasicDurationFormatter
(PeriodFormatter formatter, PeriodBuilder builder, DateFormatter fallback, long fallbackLimit, String localeName, TimeZone timeZone) -
Method Summary
Modifier and TypeMethodDescriptionprotected Period
doBuild
(long duration, long referenceDate) protected String
doFallback
(long duration, long referenceDate) protected String
formatDurationFrom
(long duration, long referenceDate) Formats a duration expressed in milliseconds from a reference date.formatDurationFromNow
(long duration) Formats a duration expressed in milliseconds.formatDurationFromNowTo
(Date targetDate) Formats the duration between now and a target date.withLocale
(String locName) Returns a new DurationFormatter that's the same as this one but formats for a new locale.withTimeZone
(TimeZone tz) Returns a new DurationFormatter that's the same as this one but uses a different time zone.
-
Field Details
-
formatter
-
builder
-
fallback
-
fallbackLimit
private long fallbackLimit -
localeName
-
timeZone
-
-
Constructor Details
-
BasicDurationFormatter
public BasicDurationFormatter(PeriodFormatter formatter, PeriodBuilder builder, DateFormatter fallback, long fallbackLimit) Creates a basic duration formatter with the given formatter, builder, and fallback. It's up to the caller to ensure that the locales and timezones of these are in sync. -
BasicDurationFormatter
protected BasicDurationFormatter(PeriodFormatter formatter, PeriodBuilder builder, DateFormatter fallback, long fallbackLimit, String localeName, TimeZone timeZone)
-
-
Method Details
-
formatDurationFromNowTo
Description copied from interface:DurationFormatter
Formats the duration between now and a target date.This is a convenience method that calls formatDurationFrom(long, long) using now as the reference date, and the difference between now and
targetDate.getTime()
as the duration.- Specified by:
formatDurationFromNowTo
in interfaceDurationFormatter
- Parameters:
targetDate
- the ending date- Returns:
- the formatted time
-
formatDurationFromNow
Description copied from interface:DurationFormatter
Formats a duration expressed in milliseconds.This is a convenience method that calls formatDurationFrom using the current system time as the reference date.
- Specified by:
formatDurationFromNow
in interfaceDurationFormatter
- Parameters:
duration
- the duration in milliseconds- Returns:
- the formatted time
-
formatDurationFrom
Description copied from interface:DurationFormatter
Formats a duration expressed in milliseconds from a reference date.The reference date allows formatters to use actual durations of variable-length periods (like months) if they wish.
The duration is expressed as the number of milliseconds in the past (negative values) or future (positive values) with respect to a reference date (expressed as milliseconds in epoch).
- Specified by:
formatDurationFrom
in interfaceDurationFormatter
- Parameters:
duration
- the duration in millisecondsreferenceDate
- the date from which to compute the duration- Returns:
- the formatted time
-
withLocale
Description copied from interface:DurationFormatter
Returns a new DurationFormatter that's the same as this one but formats for a new locale.- Specified by:
withLocale
in interfaceDurationFormatter
- Parameters:
locName
- the name of the new locale- Returns:
- a new formatter for the given locale
-
withTimeZone
Description copied from interface:DurationFormatter
Returns a new DurationFormatter that's the same as this one but uses a different time zone.- Specified by:
withTimeZone
in interfaceDurationFormatter
- Parameters:
tz
- the time zone in which to compute durations.- Returns:
- a new formatter for the given locale
-
doFallback
-
doBuild
-
doFormat
-