public class IlvDurationFormat extends Format
IlvDurationFormat
is a class that formats time durations
according to a set of rules. Each IlvDurationFormat
delegates to
an internal RuleBasedNumberFormat
that performs the actual
formatting of time durations specified in seconds. A full description of the
rule syntax can be found in the ICU4J documentation.
The Gantt duration format supports alternate locales by utilizing resource files. The resource files are documented here.
Format.Field
Modifier and Type | Field and Description |
---|---|
static int |
H_M_S
This selector code tells the constructor to create a duration formatter
that uses colon-separated numeric fields for hours, minutes, and seconds.
|
static int |
LARGEST_UNIT_MEDIUM
This selector code tells the constructor to create a formatter that
formats a duration as a floating point number of the largest time unit that
allows the quantity to be >= 1.
|
static int |
TIME_UNIT_MEDIUM
This selector code tells the constructor to create a formatter that
formats a duration as a comma-separated time units, each one being
represented by their value and a 3 or 4 letter abbreviation.
|
static int |
TIME_UNIT_SHORT
This selector code tells the constructor to create a a formatter that
formats a duration as a comma-separated time units, each one being
represented by their value and a single letter abbreviation (or more if
there is a naming conflict).
|
Constructor and Description |
---|
IlvDurationFormat()
Creates an
IlvDurationFormat from a predefined formatting
rule. |
IlvDurationFormat(int format)
Creates an
IlvDurationFormat from a predefined formatting
rule. |
IlvDurationFormat(Locale locale,
int format)
Deprecated.
This method ignores the calendar specification in the
ULocale . Please use
IlvDurationFormat(ULocale, int) instead. |
IlvDurationFormat(com.ibm.icu.util.ULocale locale,
int format)
Creates an
IlvDurationFormat from a predefined formatting
rule. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Returns whether an object is logically equal to this formatter.
|
String |
format(double duration)
Formats a duration to produce a string.
|
StringBuffer |
format(double duration,
StringBuffer toAppendTo,
FieldPosition pos)
Formats a duration and appends the resulting text to the specified
string buffer.
|
String |
format(IlvDuration duration)
Formats a duration to produce a string.
|
StringBuffer |
format(IlvDuration duration,
StringBuffer toAppendTo,
FieldPosition pos)
Formats a duration and appends the resulting text to the specified
string buffer.
|
String |
format(long duration)
Formats a duration to produce a string.
|
StringBuffer |
format(long duration,
StringBuffer toAppendTo,
FieldPosition pos)
Formats a duration and appends the resulting text to the specified
string buffer.
|
StringBuffer |
format(Object obj,
StringBuffer toAppendTo,
FieldPosition pos)
Formats an object as a duration and appends the resulting text to the
specified string buffer.
|
int |
hashCode()
Returns a hash code for this formatter.
|
boolean |
isLenientParseMode()
Returns true if lenient-parse mode is turned on.
|
IlvDuration |
parse(String text)
Parses text from the beginning of the specified string, according to this
formatter's rules to produce an
IlvDuration . |
IlvDuration |
parse(String text,
ParsePosition pos)
Parses the specified string, beginning at the specified position,
according to this formatter's rules to produce an
IlvDuration . |
Object |
parseObject(String text,
ParsePosition pos)
Parses the specified string, beginning at the specified position,
according to this formatter's rules to produce an
IlvDuration . |
void |
setLenientParseMode(boolean enabled)
Turns lenient-parse mode on and off.
|
clone, format, formatToCharacterIterator, parseObject
public static final int H_M_S
Range | Format (English locale) | Example (English locale) |
[0 sec., 60 sec.) | 0 sec. | "19.5 sec." |
[1 min., 60 min.) | 0:00 | "9:08", "20:35" |
[1 hr., ...] | 0:00:00 | "2:02:00", "17:15:05" |
public static final int LARGEST_UNIT_MEDIUM
Range | Format (English locale) | Example (English locale) |
[0 sec., 60 sec.) | 0.## sec. | "19.5 sec." |
[1 min., 60 min.) | 0.## min. | "8.2 min." |
[1 hr., 24 hr.) | 0.## hr. | "14.33 hr." |
[1 day, 7 days) | 0.## days | "2 days" | [1 wk., ...] | 0.## wk. | "11.5 wk." |
public static int TIME_UNIT_MEDIUM
Range | Format (English locale) | Example (English locale) |
[0 sec., 60 sec.] | 00 secs | "19 secs" |
[1 min., 60 min.] | 0 mins, 0 secs | "8 mins, 7 secs" |
[1 hour, 24 hours] | 0 hrs, 0 mins, 0 secs | "4 hrs, 16 min, 1 sec" |
[1 day, 7 days] | 0 days, 0 hrs, 0 mins, 0 secs | "2 days, 10 hrs, 4 mins, 3 secs" |
[1 week, ...] | 0 wks, 0 days, 0 hrs, 0 mins, 0 secs | "5 wks, 3 days, 4 hrs, 26 mins, 13 secs" |
public static int TIME_UNIT_SHORT
Range | Format (English locale) | Example (English locale) |
[0 sec., 60 sec.] | 00 s | "19s" |
[1 min., 60 min.] | 0m 0s | "8m 7s" |
[1 hour, 24 hours] | 0h 0m 0s | "4h 16m 1s" |
[1 day, 7 days] | 0d 0h 0m 0s | "2d 10h 4m 3s" |
[1 week, ...] | 0w 0d 0h 0m 0s | "5w 3d 4h 26m 13s" |
public IlvDurationFormat()
IlvDurationFormat
from a predefined formatting
rule. The format uses the current locale. The default formatting rule
used is TIME_UNIT_MEDIUM
.public IlvDurationFormat(int format)
IlvDurationFormat
from a predefined formatting
rule. The format uses the current locale.format
- A selector code specifying the type of formatter to create.
This must be one of the values: H_M_S
, LARGEST_UNIT_MEDIUM
, TIME_UNIT_MEDIUM
or TIME_UNIT_SHORT
.@Deprecated public IlvDurationFormat(Locale locale, int format)
ULocale
. Please use
IlvDurationFormat(ULocale, int)
instead.IlvDurationFormat
from a predefined formatting
rule.locale
- The locale for the formatter.format
- A selector code specifying the type of formatter to create.
This must be one of the values: H_M_S
, LARGEST_UNIT_MEDIUM
, TIME_UNIT_MEDIUM
or TIME_UNIT_SHORT
.public IlvDurationFormat(com.ibm.icu.util.ULocale locale, int format)
IlvDurationFormat
from a predefined formatting
rule.locale
- The locale for the formatter.format
- A selector code specifying the type of formatter to create.
This must be one of the values: H_M_S
, LARGEST_UNIT_MEDIUM
, TIME_UNIT_MEDIUM
or TIME_UNIT_SHORT
.public final StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
pos
argument identifies a field used by the format,
then its indices are set to the beginning and end of the first such
field encountered.format
in class Format
obj
- The duration to format, specified in seconds.toAppendTo
- The buffer to be appended with the formatted text.pos
- A FieldPosition
identifying a field in the
formatted text.toAppendTo
, with the
formatted text appended.NullPointerException
- if toAppendTo
or
pos
is null
.IllegalArgumentException
- if the format cannot format the given
object.public final StringBuffer format(IlvDuration duration, StringBuffer toAppendTo, FieldPosition pos)
pos
argument identifies a field used by the format,
then its indices are set to the beginning and end of the first such
field encountered.duration
- The duration to format.toAppendTo
- The buffer to be appended with the formatted text.pos
- A FieldPosition
identifying a field in the
formatted text.toAppendTo
, with the
formatted text appended.NullPointerException
- if toAppendTo
or pos
is null
.format(IlvDuration)
public final String format(IlvDuration duration)
format
(duration, new StringBuffer(), new FieldPosition(0)).toString();
duration
- The duration to format.public final StringBuffer format(long duration, StringBuffer toAppendTo, FieldPosition pos)
pos
argument identifies a field
used by the format, then its indices are set to the beginning and end
of the first such field encountered.duration
- The duration to format, in seconds.toAppendTo
- The buffer to be appended with the formatted text.pos
- A FieldPosition
identifying a field in the
formatted text.toAppendTo
, with the
formatted text appended.NullPointerException
- if toAppendTo
or pos
is null
.format(long)
public final String format(long duration)
format
(duration, new StringBuffer(), new FieldPosition(0)).toString();
duration
- The duration to format, in seconds.public final StringBuffer format(double duration, StringBuffer toAppendTo, FieldPosition pos)
pos
argument identifies a field used by the format,
then its indices are set to the beginning and end of the first such
field encountered.duration
- The duration to format, in seconds.toAppendTo
- The buffer to be appended with the formatted text.pos
- A FieldPosition
identifying a field in the
formatted text.toAppendTo
, with the
formatted text appended.NullPointerException
- if toAppendTo
or pos
is null
.format(double)
public final String format(double duration)
format
(duration, new StringBuffer(), new FieldPosition(0)).toString();
duration
- The duration to format, in seconds.public Object parseObject(String text, ParsePosition pos)
IlvDuration
.
This method attempts to parse text
starting at the index
given by pos
. If parsing succeeds, then the index of
pos
is updated to the index after the last character used
(parsing does not necessarily use all characters up to the end of the
string), and the parsed duration is returned.
The updated pos
can be used to indicate the starting
point for the next call to this method. If an error occurs, then the
index of pos
is not changed, the error index of
pos
is set to the index of the character where the error
occurred, and null
is returned.parseObject
in class Format
text
- The string, part of which should be parsed.pos
- On entry, contains the position of the first character in
text
to examine. On exit, has been updated to
contain the position of the first character in
text
that was not consumed by the parse.null
.public IlvDuration parse(String text, ParsePosition pos)
IlvDuration
.
This method attempts to parse text
starting at the index
given by pos
. If parsing succeeds, then the index of
pos
is updated to the index after the last character used
(parsing does not necessarily use all characters up to the end of the
string), and the parsed duration is returned.
The updated pos
can be used to indicate
the starting point for the next call to this method. If an error occurs,
then the index of pos
is not changed, the error index of
pos
is set to the index of the character where the error
occurred, and null
is returned.text
- The string, part of which should be parsed.pos
- On entry, contains the position of the first character in
text
to examine. On exit, has been updated to
contain the position of the first character in
text
that was not consumed by the parse.public IlvDuration parse(String text) throws ParseException
IlvDuration
. This method may not
use the entire text of the given string.text
- The string whose beginning should be parsed.ParseException
- if the beginning of the specified string cannot be
parsed.public void setLenientParseMode(boolean enabled)
With lenient parsing, the parser may use heuristics to interpret input that does not precisely match this object's format. With strict parsing, input must match this object's format. The default mode is false.
enabled
- If true, turns lenient-parse mode on; if false, turns it
off.RuleBasedNumberFormat.setLenientParseMode(boolean)
public boolean isLenientParseMode()
setLenientParseMode(boolean)
public int hashCode()
public boolean equals(Object obj)
true
if and only if the argument is
an IlvDurationFormat
object that represents the same
formatting rules as this formatter.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.