public class

PrettyTimeFormat

extends Format
implements FormatProvider
java.lang.Object
   ↳ java.text.Format
     ↳ humanize.time.PrettyTimeFormat

Class Overview

Format implementation for PrettyTime.

Summary

Public Constructors
PrettyTimeFormat()
PrettyTimeFormat(Locale locale)
Public Methods
Duration approximateDuration(Date then)
List<Duration> calculatePreciseDuration(Date then)
List<TimeUnit> clearUnits()
static FormatFactory factory()
String format(Date ref, Date then)
Convenience format method.
String format(List<Duration> durations)
String format(Duration duration)
String format(Date ref, Date then, long precision)
Convenience format method for precise durations.
StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
String formatUnrounded(Date then)
String formatUnrounded(Duration duration)
FormatFactory getFactory()
Gets the format factory.
TimeFormat getFormat(TimeUnit unit)
String getFormatName()
Gets the format name that will be registered.
static PrettyTimeFormat getInstance()
static PrettyTimeFormat getInstance(Locale locale)
PrettyTime getPrettyTime()
Gets the underlying PrettyTime instance.
List<TimeUnit> getUnits()
Object parseObject(String source, ParsePosition pos)
PrettyTime registerUnit(TimeUnit unit, TimeFormat format)
[Expand]
Inherited Methods
From class java.text.Format
From class java.lang.Object
From interface humanize.spi.FormatProvider

Public Constructors

public PrettyTimeFormat ()

public PrettyTimeFormat (Locale locale)

Public Methods

public Duration approximateDuration (Date then)

public List<Duration> calculatePreciseDuration (Date then)

public List<TimeUnit> clearUnits ()

public static FormatFactory factory ()

public String format (Date ref, Date then)

Convenience format method.

Parameters
ref The date of reference.
then The future date.
Returns
  • a relative format date as text representation

public String format (List<Duration> durations)

public String format (Duration duration)

public String format (Date ref, Date then, long precision)

Convenience format method for precise durations.

Parameters
ref The date of reference.
then The future date.
precision The precision to retain in milliseconds.
Returns
  • a relative format date as text representation or an empty string if no durations are retained

public StringBuffer format (Object obj, StringBuffer toAppendTo, FieldPosition pos)

public String formatUnrounded (Date then)

public String formatUnrounded (Duration duration)

public FormatFactory getFactory ()

Gets the format factory.

Returns

public TimeFormat getFormat (TimeUnit unit)

public String getFormatName ()

Gets the format name that will be registered. If you want to register multiple names for a format then return a String with the names concatenated by a vertical bar character '|'.

Returns
  • the format name

public static PrettyTimeFormat getInstance ()

public static PrettyTimeFormat getInstance (Locale locale)

public PrettyTime getPrettyTime ()

Gets the underlying PrettyTime instance.

Returns
  • the underlying PrettyTime instance.

public List<TimeUnit> getUnits ()

public Object parseObject (String source, ParsePosition pos)

public PrettyTime registerUnit (TimeUnit unit, TimeFormat format)