- java.lang.Object
-
- com.pervasive.datarush.encoding.text.IntervalFormatUtil
-
public class IntervalFormatUtil extends Object
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 Constructor Description IntervalFormatUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
formatDuration(Duration duration, String pattern)
static String
formatPeriod(Period period, String pattern)
static Duration
parseDuration(String duration, String pattern)
protected static int
parseIntField(String str, int startPos, int endPos)
protected static long
parseLongField(String str, int startPos, int endPos)
static Period
parsePeriod(String period, String pattern)
protected static long
parseSubSecondField(String str, int startPos, int endPos)
static <T extends TemporalAmount>
voidvalidatePattern(Class<T> type, String pattern)
-
-
-
Method Detail
-
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
public static String formatPeriod(Period period, String pattern) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
parsePeriod
public static Period parsePeriod(String period, String pattern) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
validatePattern
public static <T extends TemporalAmount> void validatePattern(Class<T> type, String pattern) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
parseIntField
protected static int parseIntField(String str, int startPos, int endPos)
-
parseLongField
protected static long parseLongField(String str, int startPos, int endPos)
-
parseSubSecondField
protected static long parseSubSecondField(String str, int startPos, int endPos)
-
-