TimeParser designed to quickly parse strings with a known format. This parser has been shown to perform around 20 times faster than the discovery parser. This class is not thread-safe, so clients must make sure that only one thread accesses the class at a time.
$Y-$m-$dT$H:$M:$S.$(subsec;places=3)Z
handy FieldHandler that ignores the contents. For example,
tp= TimeParser.create(sagg,"v", TimeParser.IGNORE_FIELD_HANDLER );
Create a TimeParser object, which is the fast time parser for use when a known format specification is used to parse many instances of a formatted string. For example, this would be used to interpret the times in an text file, but not times entered in a time range GUI to control an axis. This can also be and is used for filenames, for example omni2_h0_mrg1hr_$Y$(m,span=6)01_v01.cdf. Note field lengths are used when formatting the data, but when parsing often fractional components are accepted. For example, the format might be "%Y %j %H", and "2012 365 12.003" is accepted. Note also that often $(Y) is used where %{Y} is used. These are equivalent, and useful when $() interferes with parsing elsewhere. URI_Templates is a public project with translations to Java, JavaScript, and Python, and provides an specification for this. See https://github.com/hapi-server/uri-templates/wiki/Specification .
$[fieldLength]<1-char code> or
$[fieldLength]()
$[fieldLength](;qualifiers)
fieldLength=0 --> makes field length indeterminate, deliminator must follow.
$Y 4-digit year
$y 2-digit year
$j 3-digit day of year
$m 2-digit month
$b 3-char month name (jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec. Sorry, rest of world...)
$d 2-digit day
$H 2-digit hour
$M 2-digit minute
$S 2-digit second
$(milli) 3-digit milliseconds
$(ignore) skip this field
$x skip this field
$(enum) skip this field. If id is specified, then id can be retrieved.
$v skip this field
$(hrinterval;values=0,1,2,3) enumeration of part of day
$(subsec;places=6) fractional seconds (6->microseconds)
$(periodic;offset=0;start=2000-001;period=P1D)
Qualifiers:
span=
delta=
Y=2004 Also for Y,m,d,H,M,S
For example:
$(j;Y=2004) means the day-of-year, within the year 2004.
$(H;Y=2004;j=117) means the hour of day 2004-117
$(m;span=6) means the 6-month interval starting at the given month.
return the formatted range. This actually returns the range that contains the min of the given range.
return the end time of the range in units, e.g. Units.us2000
return the field handler for the id. For example, enum returns the field handler handling enumerations. Note there is currently only one field handler for each type, so for example two enumerations are not allowed.
return the field handler for the id. For example, enum returns the field handler handling enumerations. Note there is currently only one field handler for each type, so for example two enumerations are not allowed.
return the pad for the spec, like "underscore" "space" "zero" or "none" For "none", space is returned, and clients allowing special behavior should check for this.
peek at the regular expression used.
return the parsed time in the given units. Here Autoplot
Jython code shows how this is used:
from org.virbo.dataset import SemanticOps
tp= TimeParser.create("$Y-$m-$dT$H")
u= SemanticOps.lookupTimeUnits("seconds since 2014-01-01T00:00")
print tp.parse("2014-01-06T02").getTime( u )
return the parsed time as a Datum. For years less than 1990, Units.us1980 is used, otherwise Units.us2000 is used.
Returns the implicit interval as a DatumRange. For example, "Jan 1, 2003" would have a getTimeDatum of "Jan 1, 2003 00:00:00", and getDatumRange() would go from midnight to midnight. This will try to create MonthDatumRanges when possible, to keep it abstract, so for example,
This accesses time, timeWidth, orbitDatumRange, startTime.tr= tp.getTimeRange() // "Jan 2015" tr= tr.next() // "Feb 2015", not 31 days starting Feb 1
return the limits of the range we can parse. These limits come from orbit files like "$(o,sc=rbspa-pp)" or from explicit fields like "$(M,Y=1999)"
return true if the parser has a field.
return true if the string appears to be an ISO8601 time. This requires that the string contain a "T" or space and the hours and minutes components.
return true if each successive field is nested within the previous, e.g. $Y$m/$d is nested, but $Y$m/$Y$m$d is not because of the second $Y.
Provide standard means of indicating this appears to be a spec by looking for something that would assert the year.
true if the flag (startTimeOnly) was set in the spec. This is a hint to clients (FileStorageModel) using the time that it shouldn't infer that the time is bounded.
must contain T or space to delimit date and time.
parse the string, which presumably contains a time matching the
spec. A reference to the TimeParser is returned so operations can be
chained together:
tp.parse("2014-01-06T02").getTime( Units.us2000 )
Since this the TimeParser has a state, it is not safe to use simultaneously
by multiple threads. Each thread should create its own parser.
explicitly set the context for time parsing. For example, filenames are just $H$M$S.dat, and the context is "Jan 17th, 2015" Note that the context is stored internally as just a start time, so spans (e.g. 3-day) are not supported.
set the digit with the integer part, and move the fractional part to the less significant digits. Format should contain just one field, see setDigit( String format, int value ) to break up fields.
force the parser to look for delimiters. This should be called immediately after
test time parsing when the format is known. This time parser is much faster than the time parser of Test009, which must infer the format as it parses.