Search in sources :

Example 1 with TimeSpanImpl

use of lucee.runtime.type.dt.TimeSpanImpl in project Lucee by lucee.

the class HttpGetWithBody method setTimeout.

/**
 * set the value timeout
 *
 * @param timeout
 *            value to set
 * @throws ExpressionException
 */
public void setTimeout(Object timeout) throws PageException {
    if (timeout instanceof TimeSpan)
        this.timeout = (TimeSpan) timeout;
    else // seconds
    {
        int i = Caster.toIntValue(timeout);
        if (i < 0)
            throw new ApplicationException("invalid value [" + i + "] for attribute timeout, value must be a positive integer greater or equal than 0");
        this.timeout = new TimeSpanImpl(0, 0, 0, i);
    }
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationException(lucee.runtime.exp.ApplicationException) TimeSpanImpl(lucee.runtime.type.dt.TimeSpanImpl)

Example 2 with TimeSpanImpl

use of lucee.runtime.type.dt.TimeSpanImpl in project Lucee by lucee.

the class ASMUtil method cachedWithinValue.

public static Literal cachedWithinValue(Expression val) throws EvaluatorException {
    if (val instanceof Literal) {
        Literal l = (Literal) val;
        // double == days
        Double d = l.getDouble(null);
        if (d != null) {
            return val.getFactory().createLitLong(TimeSpanImpl.fromDays(d.doubleValue()).getMillis(), null, null);
        }
        return l;
    } else // createTimespan
    if (val instanceof Variable) {
        Variable var = (Variable) val;
        if (var.getMembers().size() == 1) {
            Member first = var.getFirstMember();
            if (first instanceof BIF) {
                BIF bif = (BIF) first;
                if ("createTimeSpan".equalsIgnoreCase(bif.getFlf().getName())) {
                    Argument[] args = bif.getArguments();
                    int len = ArrayUtil.size(args);
                    if (len >= 4 && len <= 5) {
                        double days = toDouble(args[0].getValue());
                        double hours = toDouble(args[1].getValue());
                        double minutes = toDouble(args[2].getValue());
                        double seconds = toDouble(args[3].getValue());
                        double millis = len == 5 ? toDouble(args[4].getValue()) : 0;
                        return val.getFactory().createLitLong(new TimeSpanImpl((int) days, (int) hours, (int) minutes, (int) seconds, (int) millis).getMillis(), null, null);
                    }
                }
            }
        }
    }
    throw cacheWithinException();
}
Also used : Variable(lucee.transformer.expression.var.Variable) Literal(lucee.transformer.expression.literal.Literal) TimeSpanImpl(lucee.runtime.type.dt.TimeSpanImpl) LitDouble(lucee.transformer.expression.literal.LitDouble) ExprDouble(lucee.transformer.expression.ExprDouble) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 3 with TimeSpanImpl

use of lucee.runtime.type.dt.TimeSpanImpl in project Lucee by lucee.

the class Query method setTimeout.

/**
 * set the value timeout The maximum number of milliseconds for the query to execute before returning an error indicating that the query has timed-out. This
 * attribute is not supported by most ODBC drivers. timeout is supported by the SQL Server 6.x or above driver. The minimum and maximum allowable values
 * vary, depending on the driver.
 *
 * @param timeout
 *            value to set
 * @throws PageException
 */
public void setTimeout(Object timeout) throws PageException {
    if (timeout instanceof TimeSpan)
        this.timeout = (TimeSpan) timeout;
    else // seconds
    {
        int i = Caster.toIntValue(timeout);
        if (i < 0)
            throw new ApplicationException("invalid value [" + i + "] for attribute timeout, value must be a positive integer greater or equal than 0");
        this.timeout = new TimeSpanImpl(0, 0, 0, i);
    }
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationException(lucee.runtime.exp.ApplicationException) TimeSpanImpl(lucee.runtime.type.dt.TimeSpanImpl)

Aggregations

TimeSpanImpl (lucee.runtime.type.dt.TimeSpanImpl)3 ApplicationException (lucee.runtime.exp.ApplicationException)2 TimeSpan (lucee.runtime.type.dt.TimeSpan)2 BIF (lucee.transformer.bytecode.expression.var.BIF)1 ExprDouble (lucee.transformer.expression.ExprDouble)1 LitDouble (lucee.transformer.expression.literal.LitDouble)1 Literal (lucee.transformer.expression.literal.Literal)1 DataMember (lucee.transformer.expression.var.DataMember)1 Member (lucee.transformer.expression.var.Member)1 Variable (lucee.transformer.expression.var.Variable)1