- java.lang.Object
-
- com.pervasive.datarush.encoding.text.TimestampParser
-
- All Implemented Interfaces:
TokenParser
public class TimestampParser extends Object
A parser producing timestamp token values from a user-defined text format. If no time zone information is provided from the text, the default time zone of the machine is used.By default, parsed values must be both syntactically and semantically correct. However, the parser can be configured to be lenient and allow values in the right format to be parsed without error. If parsing is lenient, these values will be interpreted as additional units of the field in question applied to the limit for that field. This "rollover" is applied in order of precision, from least to most precise field. For instance, under lenient parsing:
- "02/29/2013 01:60:00" will be parsed as 3/1/2013 2:00:00.
- "01/01/2013 25:00:00" will be parsed as 1/2/2013 1:00:00.
- "02/29/2013 25:60:00" will be parsed as 3/2/2013 2:00:00, adjusting first the days, then the hours, and finally the minutes.
Parsing is done using the Joda time library which uses a similar format to that described in
SimpleDateFormat
. Most specifiers compatible with the JDK are compatible with Joda time, the notable exceptions being:- The 'W' (week in month) specifier is not supported.
- The 'F' (day of week as number) specifier is replaced with 'e'.
-
-
Constructor Summary
Constructors Constructor Description TimestampParser(DateTimeFormatting format, String nullIndicator)
Creates a parser using the specified format.TimestampParser(String format)
Creates a parser using the specified format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getParseError()
Whenparse
method returns false this method can be used to retrieve the specific error message detailing why the parsing failed.boolean
parse(String text)
Parses the given text string into a token value.protected void
setParseError(String msg)
void
setTarget(ScalarSettable output)
Sets the buffer for holding parsed values.
-
-
-
Constructor Detail
-
TimestampParser
public TimestampParser(String format)
Creates a parser using the specified format. Only empty strings are treated as null. Text values are interpreted strictly.- Parameters:
format
- the input format to parse
-
TimestampParser
public TimestampParser(DateTimeFormatting format, String nullIndicator)
Creates a parser using the specified format. Empty strings and the specified text value are treated as null. Text values are interpreted strictly or leniently as indicated.- Parameters:
format
- the input format to parsenullIndicator
- the text value representing nulllenient
- indicates whether to be lenient about accepting values having the correct syntax, but not having a valid mapping.
-
-
Method Detail
-
setTarget
public final void setTarget(ScalarSettable output)
Description copied from interface:TokenParser
Sets the buffer for holding parsed values. A reference to this container is held and accessed only when an formatting is requested.- Specified by:
setTarget
in interfaceTokenParser
- Parameters:
output
- the value buffer in which to store parsed values
-
parse
public final boolean parse(String text)
Description copied from interface:TokenParser
Parses the given text string into a token value. If the parse succeeds, the result is stored in the target buffer. If it fails, the contents of the target buffer are unchanged and information regarding failure will be saved that is accessible by calling thegetParseError
method.- Specified by:
parse
in interfaceTokenParser
- Parameters:
text
- text string to convert. Callers should not assume it is safe to passnull
.- Returns:
true
if the parsing succeeded,false
otherwise.
-
setParseError
protected final void setParseError(String msg)
-
getParseError
public final String getParseError()
Description copied from interface:TokenParser
Whenparse
method returns false this method can be used to retrieve the specific error message detailing why the parsing failed. If the last parse was successful an empty string will be returned- Specified by:
getParseError
in interfaceTokenParser
- Returns:
- a message detailing any parse errors that occurred
during the last call to
parse
.
-
-