public final class TLcdDurationFormat extends Format
Format
which handles ILcdISO19103Measure
instances
which have a unit of measure
with measure type
TLcdISO19103MeasureTypeCodeExtension.DURATION
Days {DaysTextSeparator} Hours {HoursTextSeparator} Minutes {MinutesTextSeparator} Seconds {SecondsTextSeparator} TrimOptionwhere:
TL
: To trim the left part of the expression, removing the starting items equal to 0, if presentTR
: To trim the right part of the expression, removing the ending items equal to 0, if presentTLR
: to trim both left and right
TLcdDurationFormat format = new TLcdDurationFormat(TLcdDurationFormat.NON_ZERO_ONLY);
ILcdISO19103Measure measure = (ILcdISO19103Measure) format.parseObject("3h 0m 10s");
ILcdISO19103Measure measure = new TLcdISO19103Measure(3.4, TLcdUnitOfMeasureFactory.DURATION_SECONDS);
String formatted = format.format(measure);
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 |
Format.Field
Modifier and Type | Field and Description |
---|---|
static 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 } |
static String |
MINIMUM_PATTERN
This pattern only displays the items with a value above 0.
d {d } h {h } m {m } s.f {s} |
static 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 |
Constructor and Description |
---|
TLcdDurationFormat()
Creates a new
TLcdDurationFormat that will use a default pattern and Locale. |
TLcdDurationFormat(String aPattern)
Creates a new
TLcdDurationFormat that will use the specified pattern and a default Locale. |
TLcdDurationFormat(String aPattern,
Locale aLocale)
Creates a new
TLcdDurationFormat that will use the specified pattern and the specified locale. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object aO) |
StringBuffer |
format(Object aObject,
StringBuffer toAppendTo,
FieldPosition pos) |
String |
getPattern()
Returns the pattern used to format Strings into
ILcdISO19103Measure instances. |
int |
hashCode() |
Object |
parseObject(String aSource,
ParsePosition pos) |
String |
toString() |
clone, format, formatToCharacterIterator, parseObject
public static final String MINIMUM_PATTERN
d {d } h {h } m {m } s.f {s}
public static final String LONG_SEPARATORS_PATTERN
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 }
public static final String NON_ZERO_ONLY
DD {d } HH {h } MM {m } SS.f {s} TLR
public TLcdDurationFormat()
TLcdDurationFormat
that will use a default pattern and Locale.public TLcdDurationFormat(String aPattern)
TLcdDurationFormat
that will use the specified pattern and a default Locale.aPattern
- is the string representing the formatting pattern, as defined in the class documentation.IllegalArgumentException
- When aPattern
is not a valid pattern.NullPointerException
- when aPattern
is null.public TLcdDurationFormat(String aPattern, Locale aLocale)
TLcdDurationFormat
that will use the specified pattern and the specified locale.aPattern
- is the string representing the formatting pattern, as defined in the class documentation.aLocale
- the Locale
to be used to parse and format.IllegalArgumentException
- When aPattern
is not a valid pattern.NullPointerException
- when aPattern
or aLocale
is null.public String getPattern()
ILcdISO19103Measure
instances.public StringBuffer format(Object aObject, StringBuffer toAppendTo, FieldPosition pos)
public Object parseObject(String aSource, ParsePosition pos)
parseObject
in class Format