Package com.ibm.icu.impl.duration
Class BasicDurationFormatter
- java.lang.Object
-
- com.ibm.icu.impl.duration.BasicDurationFormatter
-
- All Implemented Interfaces:
DurationFormatter
class BasicDurationFormatter extends java.lang.Object implements DurationFormatter
Core implementation class for DurationFormatter.
-
-
Field Summary
Fields Modifier and Type Field Description private PeriodBuilder
builder
private DateFormatter
fallback
private long
fallbackLimit
private PeriodFormatter
formatter
private java.lang.String
localeName
private java.util.TimeZone
timeZone
-
Constructor Summary
Constructors Modifier Constructor Description BasicDurationFormatter(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, java.lang.String localeName, java.util.TimeZone timeZone)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Period
doBuild(long duration, long referenceDate)
protected java.lang.String
doFallback(long duration, long referenceDate)
protected java.lang.String
doFormat(Period period)
java.lang.String
formatDurationFrom(long duration, long referenceDate)
Formats a duration expressed in milliseconds from a reference date.java.lang.String
formatDurationFromNow(long duration)
Formats a duration expressed in milliseconds.java.lang.String
formatDurationFromNowTo(java.util.Date targetDate)
Formats the duration between now and a target date.DurationFormatter
withLocale(java.lang.String locName)
Returns a new DurationFormatter that's the same as this one but formats for a new locale.DurationFormatter
withTimeZone(java.util.TimeZone tz)
Returns a new DurationFormatter that's the same as this one but uses a different time zone.
-
-
-
Field Detail
-
formatter
private PeriodFormatter formatter
-
builder
private PeriodBuilder builder
-
fallback
private DateFormatter fallback
-
fallbackLimit
private long fallbackLimit
-
localeName
private java.lang.String localeName
-
timeZone
private java.util.TimeZone timeZone
-
-
Constructor Detail
-
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, java.lang.String localeName, java.util.TimeZone timeZone)
-
-
Method Detail
-
formatDurationFromNowTo
public java.lang.String formatDurationFromNowTo(java.util.Date targetDate)
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
public java.lang.String formatDurationFromNow(long duration)
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
public java.lang.String formatDurationFrom(long duration, long referenceDate)
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
public DurationFormatter withLocale(java.lang.String locName)
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
public DurationFormatter withTimeZone(java.util.TimeZone tz)
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
protected java.lang.String doFallback(long duration, long referenceDate)
-
doBuild
protected Period doBuild(long duration, long referenceDate)
-
doFormat
protected java.lang.String doFormat(Period period)
-
-