private static final class MulDuration extends Exec {
static final MulDuration INSTANCE = new MulDuration();
public DurationValue eval(DynamicContext dynEnv, Item v1, Item v2) throws XQueryException {
final DurationValue dur1;
final double d2;
if(v1 instanceof DurationValue) {
dur1 = (DurationValue) v1;
d2 = asDouble(v2, dynEnv);
} else {
dur1 = (DurationValue) v2;
d2 = asDouble(v1, dynEnv);
}
if(Double.isNaN(d2)) {
throw new DynamicError("err:FOCA0005", "Illegally multiplying with NaN.");
}
if(Double.isInfinite(d2)) {
throw new DynamicError("err:FODT0002", "Duration value is too large or too small to be represented.");
}
DurationType dt = dur1.getDurationType();
final Duration res;
final int dt1 = dt.getTypeId();
if(dt1 == TypeTable.YEAR_MONTH_DURATION_TID) {
int months = dur1.totalMonths();
long ym = Math.round(months * d2);
res = XsDatatypeFactory.createYearMonthDuration(ym);
} else {
Duration dv1 = dur1.getValue();
res = dv1.multiply(BigDecimal.valueOf(d2));
}
return new DurationValue(res, dt);
}