public class DayExpression extends Object
In words, a day expression is a keyword or a date followed by zero or more positive or negative offsets. The keywords are today, start and end. To be resolved as a time index, a day expression requires a context. Possible contexts a time domain or a range. The keywords start and end can only be resolved in the context of a range. For example, the expressionexpression := (today|start|end|date)(+|-integer)* date := yyyy-mm-dd
end-2+1corresponds to the upper bound of the context range, minus 1. Day expressions can be incremented without being resolved. For example, incrementing the expression
startby 2 equals
start+2.
The date part is a day in the standard daily domain. With the keywords start and end, and with literal dates, the offset is applied in the target domain, as given by the context argument when dates are returned. But with the keyword today, the offset is applied sometimes in the daily domain. It is applied in the daily domain only when the target domain resolution is finer than daily. This is for example useful when getting the last n days of a series with second resolution. In all other cases, the offset is applied in the target domain.
It is possible to use incomplete dates like a year without month and day, and they will be completed in the standard fashion, but offsets are only valid with complete daily dates.
A new day expression has no default value. Trying to resolve a new day
expression which was never set is a bug and throws an
IllegalStateException
.
Modifier and Type | Field and Description |
---|---|
static String |
END
The keyword end.
|
static String |
START
The keyword start.
|
static String |
TODAY
The keyword today.
|
Constructor and Description |
---|
DayExpression(Adjustment adjustment)
Construct a day expression with the given adjustment.
|
DayExpression(DayExpression model)
Construct a day expression as a copy of the given model.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
enforceValidRange(TimeDomain domain,
DayExpression begin,
boolean keepBegin)
Enforce a valid range between the given day expression and this
expression.
|
TimeIndex |
getDate(Range context)
Resolve the expression in the context of the given range and return the
result as a time index.
|
TimeIndex |
getDate(TimeDomain domain)
Resolve the expression in the given time domain and return the result as
a time index.
|
String |
getExpression()
Return the expression.
|
void |
incr(int increment)
Add the given increment to the expression.
|
protected boolean |
isToday()
Return true if the expression includes the keyword today.
|
protected boolean |
needContext()
Return true if the expression requires a context.
|
static Day |
parseDay(String expr)
Parse the expression as a date in the daily calendar and returns it as a
Day . |
static TimeIndex |
parseDay(String expr,
TimeDomain domain,
Adjustment adjustment)
Parse the expression as a date in the daily calendar and returns it as a TimeIndex
in the domain requested, adjusted as indicated.
|
protected void |
reset(DayExpression model)
Change the expression to match the given model.
|
void |
setExpression(TimeDomain domain,
String expression)
Set the domain and the expression.
|
protected void |
setTime(TimeIndex time)
Set the time of the expression to the given time index.
|
public static String TODAY
public static String START
public static String END
public DayExpression(Adjustment adjustment)
adjustment
- a non-null adjustmentpublic DayExpression(DayExpression model)
model
- a non-null modelpublic static Day parseDay(String expr) throws T2Exception
Day
.expr
- a non-null day expressionT2Exception
public static TimeIndex parseDay(String expr, TimeDomain domain, Adjustment adjustment) throws T2Exception
expr
- a non-null day expressiondomain
- a non-null time domainadjustment
- a non-null adjustmentT2Exception
protected boolean isToday()
protected void reset(DayExpression model)
model
- a modelprotected boolean needContext()
protected void setTime(TimeIndex time)
time
- a non-null time indexpublic void setExpression(TimeDomain domain, String expression) throws T2Exception
domain
- a non-null domainexpression
- a non-null expressionT2Exception
public void incr(int increment) throws T2Exception
increment
- a positive or negative numberT2Exception
public String getExpression()
public TimeIndex getDate(TimeDomain domain) throws T2Exception
domain
- a non-null time domainT2Exception
public TimeIndex getDate(Range context) throws T2Exception
context
- a non-null rangeT2Exception
protected boolean enforceValidRange(TimeDomain domain, DayExpression begin, boolean keepBegin) throws T2Exception
domain
- a non-null domainbegin
- a non-null day expressionkeepBegin
- if true modify this object else modify the argumentT2Exception
Copyright © 2017. All rights reserved.