| java.lang.Object org.pentaho.util.DateMath
DateMath | public class DateMath (Code) | | Provides a utility for calculating relative dates. The class calculates a
date based upon an expression. The syntax of the expression is given below.
Date Expression
<expression> := <expression>+ ( ';' DATESPEC )?
<expression> := OPERATION? OPERAND ':' <unit> <position>?
<unit> := 'Y' | 'M' | 'D' | 'W' | 'h' | 'm' | 's'
<position> := 'S' | 'E'
OPERATION := '+' | '-'
OPERAND := [0..9]+
DATESPEC := <i>any
java.text.SimpleDateFormat format pattern</i>
The OPERAND specifies the positive or negative offset to the date.
The unit inidcates the unit of the date to manipulate. The
optional position indicates the relative position for the specified unit:
S for start and E for end. The following are the valid unit
values.
Y Year
M Month
W Week
D Day
h hour
m minute
s second
Examples:
0:ME -1:DS 00:00:00.000 of the day before the last day of the current month
0:MS 0:WE 23:59:59.999 the last day of the first week of the month
0:ME 23:59:59.999 of the last day of teh current month
5:Y the current monty, day and time 5 years in the future
5:YS 00:00:00.000 of the first day of the years 5 years in the future
|
Method Summary | |
public static Calendar | calculateDate(String expression) Calculates the date specified by the expression, relative to the current
date/time. | public static Calendar | calculateDate(Calendar date, String expression) Calculates the date specified by the expression, relative to the
indicated date/time.
Parameters: date - the target date against the expression is evaluated. | public static String | calculateDateString(Calendar date, String expressionWithFormat) Calculates a date, returning the formatted string version of the
calculated date. | public static String | calculateDateString(Calendar date, String expressionWithFormat, Locale locale) Calculates a date, returning the formatted string version of the
calculated date.
Parameters: date - the target date against the expression will be applied. | public static String | claculateDateString(String expressionWithFormat) Calculates a date, returning the formatted string version of the
calculated date. |
calculateDate | public static Calendar calculateDate(String expression)(Code) | | Calculates the date specified by the expression, relative to the current
date/time. The method is a short cut for
DateMath.calculate(Calendar,String) calculate(null,expression) .
Parameters: expression - the date expression as described above. The calculated date. throws: IllegalArgumentException - if expression is invalid. |
calculateDate | public static Calendar calculateDate(Calendar date, String expression)(Code) | | Calculates the date specified by the expression, relative to the
indicated date/time.
Parameters: date - the target date against the expression is evaluated. Ifnull, the current date/time is used. If notnull, the object is manipulated by the expression. Parameters: expression - the date expression as described above. The calculated date. This will be date ifdate is not null. |
calculateDateString | public static String calculateDateString(Calendar date, String expressionWithFormat)(Code) | | Calculates a date, returning the formatted string version of the
calculated date. The method is a short cut for
DateMath.calculateDate(Calendar,String,Locale) calculateDate(date,expressionWithFormat,null) .
Parameters: date - the target date against the expression will be applied. Parameters: expressionWithFormat - the relative date expression with optional formatspecification. The calculated date as a string. throws: IllegalArgumentException - if expressionWithFormat is invalid. |
calculateDateString | public static String calculateDateString(Calendar date, String expressionWithFormat, Locale locale)(Code) | | Calculates a date, returning the formatted string version of the
calculated date.
Parameters: date - the target date against the expression will be applied. Ifnull, the current date is used. Parameters: expressionWithFormat - the relative date expression with optional formatspecification. Parameters: locale - the desired locale for the formatted string. The calculated date as a string. throws: IllegalArgumentException - if expressionWithFormat is invalid. |
claculateDateString | public static String claculateDateString(String expressionWithFormat)(Code) | | Calculates a date, returning the formatted string version of the
calculated date. The method is a short cut for
DateMath.calculateDate(Calendar,String,Locale) calculateDate(null,expressionWithFormat,null) .
If the date format is omitted, the short format for the
PentahoSystem.getLocale is used.
Parameters: expressionWithFormat - the relative date expression with optional formatspecification. The calculated date as a string. throws: IllegalArgumentException - if expressionWithFormat is invalid. |
|
|