Top Description Fields Constructors Methods
liquibase.util

public final Class NowAndTodayUtil

extends Object
Class Inheritance
Imports
liquibase.exception.DateParseException, java.util.Calendar, .Date, java.util.regex.Matcher, .Pattern

Handles 'NOW' and 'TODAY' for Date / Time type columns

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
private static final Pattern
private static final String
private static final int
private static final Pattern

Constructor Summary

AccessConstructor and Description
private
NowAndTodayUtil()

Private constructor to prevent instantiation.

Method Summary

Modifier and TypeMethod and Description
public static Date

Returns:

calculated date, or null if is not a NOW or TODAY prefixed value.
doNowOrToday
(String
value to convert to a date
value
,
String
Column type (e.g. "timestamp", "time", "date", or "datetime")
colType
)

Determines value for "NOW" or "TODAY" prefixed value.

public static boolean

Returns:

true if value starts with "NOW" or "TODAY" (case insensitive), false otherwise.
isNowOrTodayFormat
(String
value to test
value
)

Checks if date starts with "NOW" or "TODAY".

private static void
parseNow(String
original value
value
,
String
lower cased value.
lowerValue
,
Calendar
Calendar with appropriate offset applied.
c
)

Parses "NOW" type specification, and applies offset (if any) to calendar value.

private static void
parseToday(String
original value
value
,
String
lower cased value.
lowerValue
,
Calendar
Calendar with appropriate offset applied.
c
)

Parses "TODAY" type specification, and applies offset (if any) to calendar value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NOWback to summary
private static final String NOW
NOW_LENGTHback to summary
private static final int NOW_LENGTH
NOW_OFFSET_PATTERNback to summary
private static final Pattern NOW_OFFSET_PATTERN
TODAYback to summary
private static final String TODAY
TODAY_LENGTHback to summary
private static final int TODAY_LENGTH
TODAY_OFFSET_PATTERNback to summary
private static final Pattern TODAY_OFFSET_PATTERN

Constructor Detail

NowAndTodayUtilback to summary
private NowAndTodayUtil()

Private constructor to prevent instantiation.

Method Detail

doNowOrTodayback to summary
public static Date doNowOrToday(String value, String colType) throws DateParseException

Determines value for "NOW" or "TODAY" prefixed value. "NOW" format can simply be "NOW" (case insensitive), or "NOW" followed by a "+" or "=", then an integer, then a unit. "M" or "MINUTE" or "MINUTES", "H" or "HOUR" or "HOURS", "D" or "DAY" or "DAYS", "Y", "YEAR", or 'YEARS". "TODAY" format can be simply "TODAY" (case insensitive), or "TODAY" followed by a "+" or "-", then an integer, to calculate an offset from today.

Parameters
value:String

value to convert to a date

colType:String

Column type (e.g. "timestamp", "time", "date", or "datetime")

Returns:Date

calculated date, or null if is not a NOW or TODAY prefixed value.

Exceptions
DateParseException:
if colType is not one of "timestamp", "time", "date", or "datetime"
isNowOrTodayFormatback to summary
public static boolean isNowOrTodayFormat(String value)

Checks if date starts with "NOW" or "TODAY".

Parameters
value:String

value to test

Returns:boolean

true if value starts with "NOW" or "TODAY" (case insensitive), false otherwise.

parseNowback to summary
private static void parseNow(String value, String lowerValue, Calendar c) throws DateParseException

Parses "NOW" type specification, and applies offset (if any) to calendar value.

Parameters
value:String

original value

lowerValue:String

lower cased value.

c:Calendar

Calendar with appropriate offset applied.

Exceptions
DateParseException:
if anything is wrong with the NOW specification.
parseTodayback to summary
private static void parseToday(String value, String lowerValue, Calendar c) throws DateParseException

Parses "TODAY" type specification, and applies offset (if any) to calendar value.

Parameters
value:String

original value

lowerValue:String

lower cased value.

c:Calendar

Calendar with appropriate offset applied.

Exceptions
DateParseException:
if anything is wrong with the TODAY specification.