Package org.geotools.util
Class DateTimeParser
- Object
-
- DateTimeParser
-
public class DateTimeParser extends Object
Parses thetime
parameter of the request. The date, time and period are expected to be formatted according ISO-8601 standard.- Author:
- Cedric Briancon, Martin Desruisseaux, Simone Giannecchini, GeoSolutions SAS, Jonathan Meyer, Applied Information Sciences, jon@gisjedi.com, Daniele Romagnoli, GeoSolutions SAS
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DateTimeParser.FormatAndPrecision
-
Field Summary
Fields Modifier and Type Field Description static int
FLAG_GET_TIME_ON_CURRENT
FLAG to return current time when the String to be parsed is "current"static int
FLAG_GET_TIME_ON_NOW
FLAG to return current time when the String to be parsed is "now"static int
FLAG_GET_TIME_ON_PRESENT
FLAG to return current time when the String to be parsed is "present"static int
FLAG_IS_LENIENT
FLAG allowing Lenient ISO8601 format alternatives, for example, YYYYMMdd in addition to YYYY-MM-dd).static int
FLAG_SINGLE_DATE_AS_DATERANGE
FLAG to return a validity date range for dates with reduced precisionstatic String[]
LENIENT_FORMATS_DAY
static String[]
LENIENT_FORMATS_HOUR
static String[]
LENIENT_FORMATS_MILLISECOND
static String[]
LENIENT_FORMATS_MINUTE
static String[]
LENIENT_FORMATS_MONTH
static String[]
LENIENT_FORMATS_SECOND
static String[]
LENIENT_FORMATS_YEAR
static long
MILLIS_IN_DAY
Amount of milliseconds in a day.static TimeZone
UTC_TZ
UTC timezone to serve as reference
-
Constructor Summary
Constructors Constructor Description DateTimeParser()
Builds a default TimeParser with no provided maximum number of timesDateTimeParser(int maxTimes)
Parses times throwing an exception if the final list exceeds maxTimesDateTimeParser(int maxTimes, int flags)
Parses times throwing an exception if the final list exceeds maxTimes
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkMaxTimes(Set result, int maxValues)
Collection
parse(String value)
Parses the date given in parameter.static long
parsePeriod(String period)
Parses the increment part of a period and returns it in milliseconds.
-
-
-
Field Detail
-
FLAG_GET_TIME_ON_PRESENT
public static final int FLAG_GET_TIME_ON_PRESENT
FLAG to return current time when the String to be parsed is "present"- See Also:
- Constant Field Values
-
FLAG_GET_TIME_ON_NOW
public static final int FLAG_GET_TIME_ON_NOW
FLAG to return current time when the String to be parsed is "now"- See Also:
- Constant Field Values
-
FLAG_GET_TIME_ON_CURRENT
public static final int FLAG_GET_TIME_ON_CURRENT
FLAG to return current time when the String to be parsed is "current"- See Also:
- Constant Field Values
-
FLAG_IS_LENIENT
public static final int FLAG_IS_LENIENT
FLAG allowing Lenient ISO8601 format alternatives, for example, YYYYMMdd in addition to YYYY-MM-dd). See the LENIENT_FORMATS_XXX Constants for a list of supported values- See Also:
- Constant Field Values
-
FLAG_SINGLE_DATE_AS_DATERANGE
public static final int FLAG_SINGLE_DATE_AS_DATERANGE
FLAG to return a validity date range for dates with reduced precision- See Also:
- Constant Field Values
-
LENIENT_FORMATS_MILLISECOND
public static final String[] LENIENT_FORMATS_MILLISECOND
-
LENIENT_FORMATS_SECOND
public static final String[] LENIENT_FORMATS_SECOND
-
LENIENT_FORMATS_MINUTE
public static final String[] LENIENT_FORMATS_MINUTE
-
LENIENT_FORMATS_HOUR
public static final String[] LENIENT_FORMATS_HOUR
-
LENIENT_FORMATS_DAY
public static final String[] LENIENT_FORMATS_DAY
-
LENIENT_FORMATS_MONTH
public static final String[] LENIENT_FORMATS_MONTH
-
LENIENT_FORMATS_YEAR
public static final String[] LENIENT_FORMATS_YEAR
-
UTC_TZ
public static final TimeZone UTC_TZ
UTC timezone to serve as reference
-
MILLIS_IN_DAY
public static final long MILLIS_IN_DAY
Amount of milliseconds in a day.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DateTimeParser
public DateTimeParser()
Builds a default TimeParser with no provided maximum number of times
-
DateTimeParser
public DateTimeParser(int maxTimes)
Parses times throwing an exception if the final list exceeds maxTimes- Parameters:
maxTimes
- Maximum number of times to parse, or a non positive number to have no limit
-
DateTimeParser
public DateTimeParser(int maxTimes, int flags)
Parses times throwing an exception if the final list exceeds maxTimes- Parameters:
maxTimes
- Maximum number of times to parse, or a non positive number to have no limitflags
- a combination (bitwise OR) of FLAG_XXX to customize the parsing.
-
-
Method Detail
-
parse
public Collection parse(String value) throws ParseException
Parses the date given in parameter. The date format should comply to ISO-8601 standard. The string may contains either a single date, or a start time, end time and a period. In the first case, this method returns a singleton containing only the parsed date. In the second case, this method returns a list including all dates from start time up to the end time with the interval specified in thevalue
string.- Parameters:
value
- The date, time and period to parse.- Returns:
- A list of dates, or an empty list of the
value
string is null or empty. - Throws:
ParseException
- if the string can not be parsed.
-
checkMaxTimes
public void checkMaxTimes(Set result, int maxValues)
-
parsePeriod
public static long parsePeriod(String period) throws ParseException
Parses the increment part of a period and returns it in milliseconds.- Parameters:
period
- A string representation of the time increment according the ISO-8601:1988(E) standard. For example:"P1D"
= one day.- Returns:
- The increment value converted in milliseconds.
- Throws:
ParseException
- if the string can not be parsed.
-
-