Class TLcdDurationFormat

java.lang.Object
java.text.Format
com.luciad.text.TLcdDurationFormat
All Implemented Interfaces:
Serializable, Cloneable

public final class TLcdDurationFormat extends Format

Format which handles ILcdISO19103Measure instances which have a unit of measure with measure type TLcdISO19103MeasureTypeCodeExtension.DURATION

The formatting of duration is determined by the pattern string that is passed to the constructor of this class. This format looks like:
   Days {DaysTextSeparator} Hours {HoursTextSeparator} Minutes {MinutesTextSeparator} Seconds {SecondsTextSeparator} TrimOption
 
where:
  • Days can be:
    1. d : to be displayed for values > 0 and not when equal to 0
    2. D : to be always displayed, even when equal to 0
    3. Nothing, in order to not be displayed at all
  • Hours can be:
    1. h : to be displayed for values > 0 and not when equal to 0
    2. H : to be always displayed, even when equal to 0
    3. Nothing, in order to not be displayed at all
  • Minutes can be:
    1. m : to be displayed for values > 0 and not when equal to 0
    2. M : to be always displayed, even when equal to 0
    3. Nothing, in order to not be displayed at all
  • Seconds can be:
    1. s : to be displayed for values > 0 and not when equal to 0
    2. S : to be always displayed, even when equal to 0
    3. Nothing, in order to not be displayed at all
  • Each character can be repeated several times in order to force preceding zeros for small values. For example, 'sss' will add preceding zeros to the value in order to reach a length of 3 characters. No zero is added if the length of the value is 3 or more. The same applies for capitalized letters.
  • DaysTextSeparator, HoursTextSeparator, MinutesTextSeparator and SecondsTextSeparator are strings that represent the different separators. Their format is {<separator>}. A distinction between the singular and the plural versions can also be made by separating them with a ":", such as {hour:hours}, {Tag:Tage}, {seconde:secondes},...
    A white-space only separator is currently not supported.
  • The last of the Days, Hours, Minutes or Seconds items can be represented with decimals using <item>.NumberOfDecimalsOfLastDisplayed, which can be:
    1. fff...: to be displayed when the decimals are present
    2. FFF....: to be displayed even when the decimals are equal to zero
    with the amount of f or F representing the amount of decimals of the last displayed item.
  • TrimOption is an optional parameter that can be:
    1. TL : To trim the left part of the expression, removing the starting items equal to 0, if present
    2. TR : To trim the right part of the expression, removing the ending items equal to 0, if present
    3. TLR : to trim both left and right
    This parameter overrides any capital-lettered item.

Usage example

Parsing


     TLcdDurationFormat format = new TLcdDurationFormat(TLcdDurationFormat.NON_ZERO_ONLY);
     ILcdISO19103Measure measure = (ILcdISO19103Measure) format.parseObject("3h 0m 10s");
     

Formatting


     ILcdISO19103Measure measure = new TLcdISO19103Measure(3.4, TLcdUnitOfMeasureFactory.DURATION_SECONDS);
     String formatted = format.format(measure);
     

Pattern example

Pattern Result
d {d} h {hour :hours } s.ff {second:seconds}    3hours 10.40seconds
s.f {s}    10,810.4s
m.FFF {minute:minutes}    180.173minutes
h {heures}    3heures
dd {d } HHH {h}    003h
DD {d : days} HH {h :hours } MM {m :minutes}    00d 03hours 00m
DD {d : days} HH {h :hours } MM {m :minutes} TL    03hours 00m
DD {d : days} HH {h :hours } MM {m :minutes} TR    00d 03hours
DD {d : days} HH {h :hours } MM {m :minutes} TLR    03hours
Since:
2017.1
See Also:
  • Field Details

    • MINIMUM_PATTERN

      public static final String MINIMUM_PATTERN
      This pattern only displays the items with a value above 0.
      d {d } h {h } m {m } s.f {s}
      See Also:
    • LONG_SEPARATORS_PATTERN

      public static final String LONG_SEPARATORS_PATTERN
      Same as MINIMUM_PATTERN but with longer separators, with a distinction between the singular form and the plural one.
      d {day :days } h {hour :hours } m {minute :minutes } s.f {second :seconds }
      See Also:
    • NON_ZERO_ONLY

      public static final String NON_ZERO_ONLY
      This pattern displays every element and trims the expression left and right the values equal to 0.
      DD {d } HH {h } MM {m } SS.f {s} TLR
      See Also:
  • Constructor Details

    • TLcdDurationFormat

      public TLcdDurationFormat()
      Creates a new TLcdDurationFormat that will use a default pattern and Locale.
    • TLcdDurationFormat

      public TLcdDurationFormat(String aPattern)
      Creates a new TLcdDurationFormat that will use the specified pattern and a default Locale.
      Parameters:
      aPattern - is the string representing the formatting pattern, as defined in the class documentation.
      Throws:
      IllegalArgumentException - When aPattern is not a valid pattern.
      NullPointerException - when aPattern is null.
    • TLcdDurationFormat

      public TLcdDurationFormat(String aPattern, Locale aLocale)
      Creates a new TLcdDurationFormat that will use the specified pattern and the specified locale.
      Parameters:
      aPattern - is the string representing the formatting pattern, as defined in the class documentation.
      aLocale - the Locale to be used to parse and format.
      Throws:
      IllegalArgumentException - When aPattern is not a valid pattern.
      NullPointerException - when aPattern or aLocale is null.
  • Method Details