public class DateParser extends Object
DateParser.normalize("It was November 23rd to 24th 1998.")
--> "It was 1998-11-23 to 1998-11-24."
DateParser.getDate("It was 1998-11-23 to 1998-11-24.")
--> 1998, 11, 23
NumberFormatter.ISOtime(DateParser.getCalendar("November 24th 1998"))
--> 1998-12-24 T 00:00:00.00
TODO 1st century transformed to 0##-##-##. Should be 00##-##-##. Just padding
doesn't work because millenium would then be padded too much (need to
distinguish between centuries and millenias).| Modifier and Type | Field and Description |
|---|---|
static String |
DATE |
static Pattern |
DATEPATTERN |
static Pattern |
JUSTDATEPATTERN |
static String |
SDATE |
static Pattern |
SDATEPATTERN |
static Pattern |
SIMPLEYEARPATTERN
A year as a pattern
|
static Pattern |
YEARPATTERN |
| Constructor and Description |
|---|
DateParser() |
| Modifier and Type | Method and Description |
|---|---|
static Calendar |
asCalendar(int[] date)
Converts a normalized Date to a Calendar
|
static Calendar |
asCalendar(String date) |
static Calendar |
asCalendar(String[] date) |
static int[] |
asInts(String[] yearMonthDay)
Parses the normalized date into ints, putting Integer.MAX_VALUE for '#'.
|
static boolean |
disjoint(int[] date1,
int[] date2)
TRUE if the dates are disjoint, i.e.
|
static boolean |
disjoint(String[] date1,
String[] date2) |
static boolean |
disjoint(String date1,
String date2) |
static boolean |
equal(int[] date1,
int[] date2)
TRUE if the dates are exactly equal, including '#'
|
static boolean |
equal(String[] date1,
String[] date2) |
static boolean |
equal(String date1,
String date2) |
static Collection<Triple<String,Integer,Integer>> |
getAllDatePositions(CharSequence s)
Returns all the dates values and their position in the text
|
static Collection<Triple<String,Integer,Integer>> |
getAllDatePositions(CharSequence s,
Language language)
Returns all the dates values and their position in the text
|
static Collection<String> |
getAllDates(CharSequence s)
Normalizes all dates in a String
|
static Collection<String> |
getAllDates(CharSequence s,
Language language)
Normalizes all dates in a String
|
static String[] |
getDate(CharSequence d)
Returns the components of the date (year, month, day) in a normalized
date string (or null)
|
static String[] |
getDate(CharSequence d,
int[] pos)
Returns the components of the date (year, month, day) in a normalized
date string (or null) and writes the start and end position in pos[0] and
pos[1]
|
static List<String> |
getDates(CharSequence d)
Returns the dates in a normalized date string
|
static boolean |
includes(int[] date1,
int[] date2)
TRUE if the first date includes the second, e.g., 1800-##-## includes
1800-05-##
|
static boolean |
includes(String[] date1,
String[] date2) |
static boolean |
includes(String date1,
String date2) |
static boolean |
isDate(CharSequence s)
Tells whether this string is a normlized date (and nothing else)
|
static boolean |
isEarlier(int[] date1,
int[] date2)
TRUE if the first date is earlier than the second.
|
static boolean |
isEarlier(String[] date1,
String[] date2)
TRUE if the first date is earlier than the second.
|
static boolean |
isEarlier(String date1,
String date2) |
static void |
main(String[] argv)
Test routine
|
protected static boolean |
matches(String a,
String b)
TRUE if the first String matches the second
|
static String |
newDate(int y,
int m,
int d)
Creates a date-string from a day, month and year as ints
|
static String |
newDate(String y,
String m,
String d)
Creates a date-string of the form "year-month-day"
|
static String |
newSubDate(String y,
String m)
Creates a date-string of the form "year-month-day"
|
static String |
normalize(CharSequence s)
Normalizes all dates in a String
|
static String |
normalize(CharSequence s,
Language language)
Normalizes all dates in a String Note: If you bugfix something in this
version, please check for applying the same fix at the position change
tracking function below
|
static String |
normalize(CharSequence s,
Language language,
PositionTracker posTracker)
Normalizes all dates in a String keeping track of the position changes
with respect to the newly created string Note: If you bugfix something in
this version, please try and check for applying the same fix at the
non-tracking function
|
static String |
normalize(CharSequence s,
PositionTracker posTracker) |
public static final String DATE
public static final Pattern DATEPATTERN
public static final Pattern JUSTDATEPATTERN
public static final String SDATE
public static final Pattern SDATEPATTERN
public static final Pattern SIMPLEYEARPATTERN
public static final Pattern YEARPATTERN
public static final String newDate(String y, String m, String d)
public static final String newDate(int y, int m, int d)
public static final String newSubDate(String y, String m)
public static String normalize(CharSequence s)
public static String normalize(CharSequence s, Language language)
public static String normalize(CharSequence s, PositionTracker posTracker)
public static String normalize(CharSequence s, Language language, PositionTracker posTracker)
public static Collection<String> getAllDates(CharSequence s)
public static Collection<String> getAllDates(CharSequence s, Language language)
public static Collection<Triple<String,Integer,Integer>> getAllDatePositions(CharSequence s)
public static Collection<Triple<String,Integer,Integer>> getAllDatePositions(CharSequence s, Language language)
public static String[] getDate(CharSequence d, int[] pos)
public static List<String> getDates(CharSequence d)
public static String[] getDate(CharSequence d)
public static boolean isDate(CharSequence s)
public static Calendar asCalendar(int[] date)
protected static boolean matches(String a, String b)
public static int[] asInts(String[] yearMonthDay)
public static boolean isEarlier(int[] date1,
int[] date2)
public static boolean isEarlier(String[] date1, String[] date2)
public static boolean includes(int[] date1,
int[] date2)
public static boolean equal(int[] date1,
int[] date2)
public static boolean disjoint(int[] date1,
int[] date2)
Copyright © 2018. All rights reserved.