Class BasicDurationFormatter

java.lang.Object
com.ibm.icu.impl.duration.BasicDurationFormatter
All Implemented Interfaces:
DurationFormatter

class BasicDurationFormatter extends Object implements DurationFormatter
Core implementation class for DurationFormatter.
  • Field Details

  • 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

      public String formatDurationFromNowTo(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 interface DurationFormatter
      Parameters:
      targetDate - the ending date
      Returns:
      the formatted time
    • formatDurationFromNow

      public 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 interface DurationFormatter
      Parameters:
      duration - the duration in milliseconds
      Returns:
      the formatted time
    • formatDurationFrom

      public 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 interface DurationFormatter
      Parameters:
      duration - the duration in milliseconds
      referenceDate - the date from which to compute the duration
      Returns:
      the formatted time
    • withLocale

      public DurationFormatter withLocale(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 interface DurationFormatter
      Parameters:
      locName - the name of the new locale
      Returns:
      a new formatter for the given locale
    • withTimeZone

      public DurationFormatter withTimeZone(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 interface DurationFormatter
      Parameters:
      tz - the time zone in which to compute durations.
      Returns:
      a new formatter for the given locale
    • doFallback

      protected String doFallback(long duration, long referenceDate)
    • doBuild

      protected Period doBuild(long duration, long referenceDate)
    • doFormat

      protected String doFormat(Period period)