java.lang.Object
com.pervasive.datarush.encoding.text.IntervalFormatUtil
A simple formatter/parser utility for TemporalAmounts such as Duration and Period.
Since there is much less variation in the possible display a simpler format is
used than in other temporal formats.
The format is denoted with a pattern string composed of various characters representing
the amounts combined with optional literal characters.
The characters that represent the various units are as follows.
Y - Years
M - Months
W - Weeks
D - Days
H - Hours
m - Minutes
s - Seconds
S - Milliseconds
n - Nanoseconds
Since intervals are represented as a collection of numeric values a single letter
represents each quantity. Any of these may optionally be used as a literal character
by escaping the character with a \. If any other characters are used in the format they
are assumed to be literals. It is best to delimit each unit with a whitespace or literal
to prevent parsing issues.
The standard ISO format for Duration can be represented as \PD\D\TH\Hm\Ms.n\S in this format.
The standard ISO format for Period can be represented as \PY\YM\MW\WD\D in this format.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDuration(Duration duration, String pattern) static StringformatPeriod(Period period, String pattern) static DurationparseDuration(String duration, String pattern) protected static intparseIntField(String str, int startPos, int endPos) protected static longparseLongField(String str, int startPos, int endPos) static PeriodparsePeriod(String period, String pattern) protected static longparseSubSecondField(String str, int startPos, int endPos) static <T extends TemporalAmount>
voidvalidatePattern(Class<T> type, String pattern)
-
Constructor Details
-
IntervalFormatUtil
public IntervalFormatUtil()
-
-
Method Details
-
formatDuration
public static String formatDuration(Duration duration, String pattern) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseDuration
public static Duration parseDuration(String duration, String pattern) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
formatPeriod
- Throws:
IllegalArgumentException
-
parsePeriod
- Throws:
IllegalArgumentException
-
validatePattern
public static <T extends TemporalAmount> void validatePattern(Class<T> type, String pattern) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
parseIntField
-
parseLongField
-
parseSubSecondField
-