public class DateTimeScanner extends Object
TimeIndex
objects.
Here is an example of use:
String pattern = "\\S+ (\\S+) (\\d+) (\\d\\d):(\\d\\d):(\\d\\d) \\S+ (\\d\\d\\d\\d)"; int[] groups = {6, 1, 2, 3, 4, 5}; String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; DateTimeScanner scanner = new DateTimeScanner(pattern, groups); scanner.setMonths(months); TimeIndex time = scanner.scan(DateTime.DOMAIN, "Wed Nov 30 12:29:23 UTC 2010"); assertEquals("2010-11-30 12:29:23", time.toString());
Constructor and Description |
---|
DateTimeScanner(String pattern,
int[] groups)
Construct a date time scanner with the given pattern and groups.
|
Modifier and Type | Method and Description |
---|---|
TimeIndex |
scan(String date)
Scan the date using the default domain.
|
TimeIndex |
scan(TimeDomain domain,
String date)
Scan the date in the given time domain.
|
void |
setDomain(TimeDomain domain)
Set the default time domain.
|
void |
setMonths(String[] keywords)
Define textual months.
|
void |
setTwoDigitYearThreshold(int threshold)
Set a threshold to trigger special handling of two digit years.
|
public DateTimeScanner(String pattern, int[] groups) throws T2Exception
Pattern
. If the pattern is null, scanning is
done directly by TimeDomain.time(String)
. Group indexes can be
specified in an array, with 1 for the first group. When the groups array
is null, group indexes are assumed to be in increasing sequence. Group
indexes are useless when the pattern is null.pattern
- a pattern or nullgroups
- an array of indexes or nullT2Exception
public void setDomain(TimeDomain domain)
scan(String)
.domain
- a time domainpublic void setMonths(String[] keywords)
keywords
- an array of 12 month keywordspublic void setTwoDigitYearThreshold(int threshold)
By default the threshold is negative, and there is no special handling of two digit years.
threshold
- public TimeIndex scan(String date) throws T2Exception
setDomain(TimeDomain)
.date
- a non-null date/timeT2Exception
public TimeIndex scan(TimeDomain domain, String date) throws T2Exception
domain
- a non-null time domaindate
- a non-null date/timeT2Exception
Copyright © 2017. All rights reserved.