Package org.openrefine.expr.util
Class CalendarParser
- java.lang.Object
-
- org.openrefine.expr.util.CalendarParser
-
public class CalendarParser extends Object
A parser for arbitrary date/time strings.
-
-
Field Summary
Fields Modifier and Type Field Description static intDD_MM_YYday/month/year order.static intDD_YY_MMday/year/month order.static intMM_DD_YYmonth/day/year order.static intMM_YY_DDmonth/year/day order.static intMONTH_AFTER_DAYbit indicating that the month comes after the day.static intMONTH_BEFORE_DAYbit indicating that the month comes before the day.static intYEAR_AFTER_DAYbit indicating that the year comes after the day.static intYEAR_AFTER_MONTHbit indicating that the year comes after the month.static intYEAR_BEFORE_DAYbit indicating that the year comes before the day.static intYEAR_BEFORE_MONTHbit indicating that the year comes before the month.static intYY_DD_MMyear/day/month order.static intYY_MM_DDyear/month/day order.
-
Constructor Summary
Constructors Constructor Description CalendarParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetOrderString(int order)Return a string representation of the order value.static intmonthNameToNumber(String str)Convert the supplied month name to its numeric representation.static Calendarparse(String dateStr)Extract a date from a string, defaulting to YY-MM-DD order for all-numeric strings.static Calendarparse(String dateStr, int order)Extract a date from a string.static Calendarparse(String dateStr, int order, boolean ignoreChanges)Extract a date from a string.static OffsetDateTimeparseAsOffsetDateTime(String dateStr)static OffsetDateTimeparseAsOffsetDateTime(String dateStr, int order)static OffsetDateTimeparseAsOffsetDateTime(String dateStr, int order, boolean ignoreChanges)static StringprettyString(Calendar cal)Return a printable representation of the date.static StringtoSQLString(Calendar cal)Return a string representation of the date suitable for use in an SQL statement.static StringtoString(Calendar cal)Return a basic representation of the string.
-
-
-
Field Detail
-
YEAR_BEFORE_MONTH
public static final int YEAR_BEFORE_MONTH
bit indicating that the year comes before the month.- See Also:
- Constant Field Values
-
YEAR_BEFORE_DAY
public static final int YEAR_BEFORE_DAY
bit indicating that the year comes before the day.- See Also:
- Constant Field Values
-
MONTH_BEFORE_DAY
public static final int MONTH_BEFORE_DAY
bit indicating that the month comes before the day.- See Also:
- Constant Field Values
-
YEAR_AFTER_MONTH
public static final int YEAR_AFTER_MONTH
bit indicating that the year comes after the month.- See Also:
- Constant Field Values
-
YEAR_AFTER_DAY
public static final int YEAR_AFTER_DAY
bit indicating that the year comes after the day.- See Also:
- Constant Field Values
-
MONTH_AFTER_DAY
public static final int MONTH_AFTER_DAY
bit indicating that the month comes after the day.- See Also:
- Constant Field Values
-
DD_MM_YY
public static final int DD_MM_YY
day/month/year order.- See Also:
- Constant Field Values
-
MM_DD_YY
public static final int MM_DD_YY
month/day/year order.- See Also:
- Constant Field Values
-
MM_YY_DD
public static final int MM_YY_DD
month/year/day order.- See Also:
- Constant Field Values
-
DD_YY_MM
public static final int DD_YY_MM
day/year/month order.- See Also:
- Constant Field Values
-
YY_DD_MM
public static final int YY_DD_MM
year/day/month order.- See Also:
- Constant Field Values
-
YY_MM_DD
public static final int YY_MM_DD
year/month/day order.- See Also:
- Constant Field Values
-
-
Method Detail
-
getOrderString
public static final String getOrderString(int order)
Return a string representation of the order value.- Parameters:
order- order- Returns:
- order string
-
monthNameToNumber
public static int monthNameToNumber(String str)
Convert the supplied month name to its numeric representation.
For example,"January"(or any substring) would return1and"December"would return12.- Parameters:
str- month name- Returns:
- the numeric month, or
UNSETif the supplied string is not a valid month name.
-
parse
public static final Calendar parse(String dateStr) throws CalendarParserException
Extract a date from a string, defaulting to YY-MM-DD order for all-numeric strings.- Parameters:
dateStr- date string- Returns:
- parsed date
- Throws:
CalendarParserException- if there was a problem parsing the string.
-
parseAsOffsetDateTime
public static final OffsetDateTime parseAsOffsetDateTime(String dateStr) throws CalendarParserException
- Throws:
CalendarParserException
-
parse
public static final Calendar parse(String dateStr, int order) throws CalendarParserException
Extract a date from a string.- Parameters:
dateStr- date stringorder- order in which pieces of numeric strings are assigned (should be one ofYY_MM_DD,MM_DD_YY, etc.)- Returns:
- parsed date
- Throws:
CalendarParserException- if there was a problem parsing the string.
-
parseAsOffsetDateTime
public static final OffsetDateTime parseAsOffsetDateTime(String dateStr, int order) throws CalendarParserException
- Throws:
CalendarParserException
-
parse
public static final Calendar parse(String dateStr, int order, boolean ignoreChanges) throws CalendarParserException
Extract a date from a string.- Parameters:
dateStr- date stringorder- order in which pieces of numeric strings are assigned (should be one ofYY_MM_DD,MM_DD_YY, etc.)ignoreChanges- iftrue, ignore date changes such asFeb 31being changed toMar 3.- Returns:
- parsed date
- Throws:
CalendarParserException- if there was a problem parsing the string.
-
parseAsOffsetDateTime
public static final OffsetDateTime parseAsOffsetDateTime(String dateStr, int order, boolean ignoreChanges) throws CalendarParserException
- Throws:
CalendarParserException
-
prettyString
public static final String prettyString(Calendar cal)
Return a printable representation of the date.- Parameters:
cal- calendar to convert to a string- Returns:
- a printable string.
-
toString
public static final String toString(Calendar cal)
Return a basic representation of the string.- Parameters:
cal- calendar to convert to a string- Returns:
- the basic string.
-
-