com.ibm.icu.text
Class DurationFormat

java.lang.Object
  extended by java.text.Format
      extended by com.ibm.icu.text.UFormat
          extended by com.ibm.icu.text.DurationFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public abstract class DurationFormat
extends UFormat

This class implements a formatter over a duration in time such as "2 days from now" or "3 hours ago".

See Also:
Serialized Form
Status:
Stable ICU 3.8.

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
protected DurationFormat()
          Deprecated. This API is ICU internal only.
protected DurationFormat(ULocale locale)
          Deprecated. This API is ICU internal only.
 
Method Summary
abstract  java.lang.StringBuffer format(java.lang.Object object, java.lang.StringBuffer toAppend, java.text.FieldPosition pos)
          Format an arbitrary object.
abstract  java.lang.String formatDurationFrom(long duration, long referenceDate)
          Formats a duration expressed in milliseconds from a reference date.
abstract  java.lang.String formatDurationFromNow(long duration)
          Formats a duration expressed in milliseconds.
abstract  java.lang.String formatDurationFromNowTo(java.util.Date targetDate)
          Formats the duration between now and a target date.
static DurationFormat getInstance(ULocale locale)
          Construct a duration format for the specified locale
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
          DurationFormat cannot parse, by default.
 
Methods inherited from class com.ibm.icu.text.UFormat
getLocale
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DurationFormat

protected DurationFormat()
Deprecated. This API is ICU internal only.

Subclass interface

Status:
Internal. This API is ICU internal only.

DurationFormat

protected DurationFormat(ULocale locale)
Deprecated. This API is ICU internal only.

Subclass interface

Status:
Internal. This API is ICU internal only.
Method Detail

getInstance

public static DurationFormat getInstance(ULocale locale)
Construct a duration format for the specified locale

Status:
Stable ICU 3.8.

format

public abstract java.lang.StringBuffer format(java.lang.Object object,
                                              java.lang.StringBuffer toAppend,
                                              java.text.FieldPosition pos)
Format an arbitrary object. Defaults to a call to formatDurationFromNow() for either Long or Date objects.

Specified by:
format in class java.text.Format
Parameters:
object - the object to format. Should be either a Long, Date, or javax.xml.datatype.Duration object.
toAppend - the buffer to append to
pos - the field position, may contain additional error messages.
Returns:
the toAppend buffer
Status:
Stable ICU 3.8.

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    java.text.ParsePosition pos)
DurationFormat cannot parse, by default. This method will throw an UnsupportedOperationException.

Specified by:
parseObject in class java.text.Format
Status:
Stable ICU 3.8.

formatDurationFromNowTo

public abstract java.lang.String formatDurationFromNowTo(java.util.Date targetDate)
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.

Parameters:
targetDate - the ending date
Returns:
the formatted time
Status:
Stable ICU 3.8.

formatDurationFromNow

public abstract java.lang.String formatDurationFromNow(long duration)
Formats a duration expressed in milliseconds.

This is a convenience method that calls formatDurationFrom using the current system time as the reference date.

Parameters:
duration - the duration in milliseconds
Returns:
the formatted time
Status:
Stable ICU 3.8.

formatDurationFrom

public abstract java.lang.String formatDurationFrom(long duration,
                                                    long referenceDate)
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).

Parameters:
duration - the duration in milliseconds
referenceDate - the date from which to compute the duration
Returns:
the formatted time
Status:
Stable ICU 3.8.


Copyright (c) 2011 IBM Corporation and others.