public class DateMath extends Object
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 the current month 5:Y the current month, 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 and Description |
---|
DateMath() |
Modifier and Type | Method and Description |
---|---|
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.
|
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.Copyright © 2017 Hitachi Vantara. All rights reserved.