Class TimeSpanFormatter<U,​S extends TimeSpan<U>>

java.lang.Object
net.time4j.format.TimeSpanFormatter<U,​S>
Type Parameters:
U - generic type of time units
S - generic type of supported timespan
Direct Known Subclasses:
Duration.Formatter, MachineTime.Formatter

public abstract class TimeSpanFormatter<U,​S extends TimeSpan<U>> extends Object

Represents a non-localized and user-defined format for timespans based on a pattern containing some standard symbols and literals.

Since:
3.26/4.22
  • Method Details

    • getPattern

      public String getPattern()

      Yields the underlying format pattern.

      Returns:
      String
    • getType

      public Class<U> getType()

      Yields the associated reified unit type.

      Returns:
      Class
    • format

      public String format(TimeSpan<? super U> duration)

      Creates a textual output of given duration.

      Parameters:
      duration - duration object
      Returns:
      textual representation of duration
      Throws:
      IllegalArgumentException - if some aspects of duration prevents printing (for example too many nanoseconds)
    • print

      public void print(TimeSpan<? super U> duration, Appendable buffer) throws IOException

      Creates a textual output of given duration and writes to the buffer.

      Parameters:
      duration - duration object
      buffer - I/O-buffer where the result is written to
      Throws:
      IllegalArgumentException - if some aspects of duration prevents printing (for example too many nanoseconds)
      IOException - if writing into buffer fails
    • parse

      public S parse(CharSequence text) throws ParseException

      Equivalent to parse(text, 0).

      Parameters:
      text - custom textual representation to be parsed
      Returns:
      parsed duration
      Throws:
      ParseException - (for example in case of mixed signs or if trailing unparsed characters exist)
      See Also:
      parse(CharSequence, int)
    • parse

      public S parse(CharSequence text, int offset) throws ParseException

      Analyzes given text according to format pattern and parses the text to a duration.

      Parameters:
      text - custom textual representation to be parsed
      offset - start position for the parser
      Returns:
      parsed duration
      Throws:
      ParseException - (for example in case of mixed signs or if trailing unparsed characters exist)