public class AdvancedDateParser extends Object
A valid expression is defined by the following grammar:
ROOT ::= (MODIFIER ",")* (":")? ("now" | DATE)? (("+" | "-") NUMBER (UNIT)?)
UNIT ::= ("day" | "days" | "week" | "weeks" | "month" | "months" | "year" | "years")
NUMBER ::=(0-9)+
DATE ::= GERMAN_DATE | ENGLISH_DATE | YM_EXPRESSION
GERMAN_DATE ::= NUMBER "." NUMBER ("." NUMBER)? (NUMBER (":" NUMBER (":" NUMBER)?)?)?
ENGLISH_DATE ::= NUMBER "/" NUMBER ("/" NUMBER)? (NUMBER (":" NUMBER (":" NUMBER)?)?)? ("am" |
"pm")?)?
YM_EXPRESSION ::= NUMBER
MODIFIER ::= ("start" | "end") ("of")? ("day" | "week" | "month" | "year")
Examples
now
- actual date1.1
- first of january of current year+1
or now + 1 day
- tomorrowstart of week: now - 1 year
- start of the week of day one year agoModifier and Type | Class and Description |
---|---|
static class |
AdvancedDateParser.DateSelection
Combines the parsed text along with the effective date (as Calendar).
|
Constructor and Description |
---|
AdvancedDateParser(String lang)
Creates a new parser for the given language to use.
|
Modifier and Type | Method and Description |
---|---|
AdvancedDateParser.DateSelection |
parse(String input)
Parses the given input and returns a DateSelection as result.
|
public AdvancedDateParser(String lang)
lang
- contains the two letter language code to obtain the translations for the available modifiers etc.public AdvancedDateParser.DateSelection parse(String input) throws ParseException
Note that an AdvancedDateParser is stateful an is therefore neither reusable nor thread-safe.
input
- the text to parseParseException
- if the input cannot be parsed as it does not conform to the given grammarCopyright © 2018. All rights reserved.