use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.
the class ParserUtils method parseExpressionDate.
/**
* Parse a date. The input format is guaranteed by the expression parser to
* be yyyy-m-d where m and d may be either 1 or 2 digits each.
*
* @param dateString the date string
* @return the parsed date
*/
public static Date parseExpressionDate(String dateString) {
String[] dateParts = dateString.split("-");
String fixedDateString = dateParts[0] + "-" + (dateParts[1].length() == 1 ? "0" : "") + dateParts[1] + "-" + (dateParts[2].length() == 1 ? "0" : "") + dateParts[2];
Date date;
try {
date = parseDate(fixedDateString);
} catch (Exception e) {
throw new ParserExceptionWithoutContext("Invalid date: " + dateString + " " + e.getMessage());
}
if (date == null) {
throw new ParserExceptionWithoutContext("Invalid date: " + dateString);
}
return date;
}
use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.
the class ItemConstant method getDescription.
@Override
public Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
Constant constant = visitor.getConstantMap().get(ctx.uid0.getText());
if (constant == null) {
throw new ParserExceptionWithoutContext("No constant defined for " + ctx.uid0.getText());
}
visitor.getItemDescriptions().put(ctx.getText(), constant.getDisplayName());
return DOUBLE_VALUE_IF_NULL;
}
Aggregations