* @throws T2Exception
*/
public Range getRange(Range context) throws T2Exception {
TimeDomain contextDomain = context.getTimeDomain();
if (beginExpr == null) {
return new Range(contextDomain);
} else {
// be more permissive with context and fix ranges invalidated by conversion
TimeIndex begin = beginExpr.getDate(context);
TimeIndex end = endExpr.getDate(context);
if (begin == null || end == null) // (consequence of empty context range when context needed)
return new Range(contextDomain);
else if (begin.compareTo(end) > 0 && (beginExpr.needContext() || endExpr.needContext()))
return new Range(contextDomain);
else {
/*
* There is a possibly that a valid range has been converted
* into an invalid one. Typical case: daily(Sat, Sat) turned
* into MoFr(Mon,Fri) because of adjustments. As this is not
* the intended effect of adjustments, the problem is fixed
* silently here.
*/
if (begin.compareTo(end) > 0 && beginAdj == Adjustment.UP) {
beginExpr.setTime(end);
begin = beginExpr.getDate(context);
}
return new Range(begin, end);
}
}
}