Package com.google.refine.expr.util
Class CalendarParser
java.lang.Object
com.google.refine.expr.util.CalendarParser
A parser for arbitrary date/time strings.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intday/month/year order.static final intday/year/month order.static final intmonth/day/year order.static final intmonth/year/day order.static final intbit indicating that the month comes after the day.static final intbit indicating that the month comes before the day.static final intbit indicating that the year comes after the day.static final intbit indicating that the year comes after the month.static final intbit indicating that the year comes before the day.static final intbit indicating that the year comes before the month.static final intyear/day/month order.static final intyear/month/day order. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final 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 final CalendarExtract a date from a string, defaulting to YY-MM-DD order for all-numeric strings.static final CalendarExtract a date from a string.static final CalendarExtract a date from a string.static final OffsetDateTimeparseAsOffsetDateTime(String dateStr) static final OffsetDateTimeparseAsOffsetDateTime(String dateStr, int order) static final OffsetDateTimeparseAsOffsetDateTime(String dateStr, int order, boolean ignoreChanges) static final StringprettyString(Calendar cal) Return a printable representation of the date.static final StringtoSQLString(Calendar cal) Return a string representation of the date suitable for use in an SQL statement.static final StringReturn a basic representation of the string.
-
Field Details
-
YEAR_BEFORE_MONTH
public static final int YEAR_BEFORE_MONTHbit indicating that the year comes before the month.- See Also:
-
YEAR_BEFORE_DAY
public static final int YEAR_BEFORE_DAYbit indicating that the year comes before the day.- See Also:
-
MONTH_BEFORE_DAY
public static final int MONTH_BEFORE_DAYbit indicating that the month comes before the day.- See Also:
-
YEAR_AFTER_MONTH
public static final int YEAR_AFTER_MONTHbit indicating that the year comes after the month.- See Also:
-
YEAR_AFTER_DAY
public static final int YEAR_AFTER_DAYbit indicating that the year comes after the day.- See Also:
-
MONTH_AFTER_DAY
public static final int MONTH_AFTER_DAYbit indicating that the month comes after the day.- See Also:
-
DD_MM_YY
public static final int DD_MM_YYday/month/year order.- See Also:
-
MM_DD_YY
public static final int MM_DD_YYmonth/day/year order.- See Also:
-
MM_YY_DD
public static final int MM_YY_DDmonth/year/day order.- See Also:
-
DD_YY_MM
public static final int DD_YY_MMday/year/month order.- See Also:
-
YY_DD_MM
public static final int YY_DD_MMyear/day/month order.- See Also:
-
YY_MM_DD
public static final int YY_MM_DDyear/month/day order.- See Also:
-
-
Constructor Details
-
CalendarParser
public CalendarParser()
-
-
Method Details
-
getOrderString
Return a string representation of the order value.- Parameters:
order- order- Returns:
- order string
-
monthNameToNumber
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
CalendarParser.UNSETif the supplied string is not a valid month name.
-
parse
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
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
Return a printable representation of the date.- Parameters:
cal- calendar to convert to a string- Returns:
- a printable string.
-
toString
Return a basic representation of the string.- Parameters:
cal- calendar to convert to a string- Returns:
- the basic string.
-
toSQLString
Return a string representation of the date suitable for use in an SQL statement.- Parameters:
cal- calendar to convert to a string- Returns:
- the SQL-friendly string.
-