|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.pentaho.platform.util.DateMath
public class DateMath
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 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
Constructor Summary | |
---|---|
DateMath()
|
Method Summary | |
---|---|
static Calendar |
calculateDate(Calendar date,
String expression)
Calculates the date specified by the expression, relative to the indicated date/time. |
static Calendar |
calculateDate(String expression)
Calculates the date specified by the expression, relative to the current date/time. |
static String |
calculateDateString(Calendar date,
String expressionWithFormat)
Calculates a date, returning the formatted string version of the calculated date. |
static String |
calculateDateString(Calendar date,
String expressionWithFormat,
Locale locale)
Calculates a date, returning the formatted string version of the calculated date. |
static String |
claculateDateString(String expressionWithFormat)
Calculates a date, returning the formatted string version of the calculated date. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DateMath()
Method Detail |
---|
public static String claculateDateString(String expressionWithFormat)
calculateDate(null,expressionWithFormat,null)
.
If the date format is omitted, the short format for the
PentahoSystem#getLocale()
is used.
expressionWithFormat
- the relative date expression with optional format
specification.
IllegalArgumentException
- if expressionWithFormat is invalid.public static String calculateDateString(Calendar date, String expressionWithFormat)
calculateDate(date,expressionWithFormat,null)
.
date
- the target date against the expression will be applied.expressionWithFormat
- the relative date expression with optional format
specification.
IllegalArgumentException
- if expressionWithFormat is invalid.public static String calculateDateString(Calendar date, String expressionWithFormat, Locale locale)
date
- the target date against the expression will be applied. If
null, the current date is used.expressionWithFormat
- the relative date expression with optional format
specification.locale
- the desired locale for the formatted string.
IllegalArgumentException
- if expressionWithFormat is invalid.public static Calendar calculateDate(String expression)
calculate(null,expression)
.
expression
- the date expression as described above.
IllegalArgumentException
- if expression is invalid.public static Calendar calculateDate(Calendar date, String expression)
date
- the target date against the expression is evaluated. If
null, the current date/time is used. If not
null, the object is manipulated by the expression.expression
- the date expression as described above.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |