Search in sources :

Example 1 with WrapTime

use of php.runtime.ext.core.classes.time.WrapTime in project jphp by jphp-compiler.

the class UXMaterialTimePicker method getValueAsTime.

@Getter
public WrapTime getValueAsTime(Environment env) {
    initFormat();
    LocalTime value = getWrappedObject().getValue();
    if (value == null) {
        return null;
    }
    Instant instant = value.atDate(LocalDate.of(0, 0, 0)).atZone(ZoneId.systemDefault()).toInstant();
    return new WrapTime(env, Date.from(instant));
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) Getter(php.runtime.annotation.Reflection.Getter)

Example 2 with WrapTime

use of php.runtime.ext.core.classes.time.WrapTime in project jphp by jphp-compiler.

the class PSqlStatement method bind.

@Signature
public void bind(Environment env, int index, Memory value) throws SQLException {
    if (value.instanceOf(WrapTime.class)) {
        WrapTime time = value.toObject(WrapTime.class);
        statement.setDate(index + 1, new Date(time.getDate().getTime()), time.getCalendar());
    } else if (value.instanceOf(Stream.class)) {
        statement.setBlob(index + 1, Stream.getInputStream(env, value));
    } else if (value.toValue() instanceof BinaryMemory) {
        statement.setBytes(index + 1, value.getBinaryBytes(env.getDefaultCharset()));
    } else {
        if (value.isNull()) {
            statement.setNull(index + 1, Types.NULL);
        } else {
            switch(value.getRealType()) {
                case INT:
                    statement.setLong(index + 1, value.toLong());
                    break;
                case DOUBLE:
                    statement.setDouble(index + 1, value.toDouble());
                    break;
                case BOOL:
                    statement.setBoolean(index + 1, value.toBoolean());
                    break;
                default:
                    statement.setString(index + 1, value.toString());
            }
        }
    }
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) BinaryMemory(php.runtime.memory.BinaryMemory) Stream(php.runtime.ext.core.classes.stream.Stream) InputStream(java.io.InputStream) Signature(php.runtime.annotation.Reflection.Signature)

Example 3 with WrapTime

use of php.runtime.ext.core.classes.time.WrapTime in project jphp by jphp-compiler.

the class PSqlStatement method bindTimestamp.

@Signature
public void bindTimestamp(Environment env, int index, Memory value) throws SQLException {
    if (value.instanceOf(WrapTime.class)) {
        WrapTime time = value.toObject(WrapTime.class);
        statement.setTimestamp(index + 1, new Timestamp(time.getDate().getTime()), time.getCalendar());
    } else {
        statement.setTimestamp(index + 1, new Timestamp(value.toLong()));
    }
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) Signature(php.runtime.annotation.Reflection.Signature)

Example 4 with WrapTime

use of php.runtime.ext.core.classes.time.WrapTime in project jphp by jphp-compiler.

the class UXDatePicker method getValueAsTime.

@Getter
public WrapTime getValueAsTime(Environment env) {
    initFormat();
    LocalDate value = getWrappedObject().getValue();
    if (value == null) {
        return null;
    }
    return new WrapTime(env, Date.from(value.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) LocalDate(java.time.LocalDate)

Example 5 with WrapTime

use of php.runtime.ext.core.classes.time.WrapTime in project jphp by jphp-compiler.

the class PSqlResult method getTyped.

public Memory getTyped(Environment env, int index) throws SQLException {
    index += 1;
    ResultSet set = resultSet;
    int type = metaData.getColumnType(index);
    if (set.getObject(index) == null) {
        return Memory.NULL;
    }
    switch(type) {
        case Types.INTEGER:
        case Types.SMALLINT:
        case Types.TINYINT:
        case Types.BIT:
            return LongMemory.valueOf(set.getLong(index));
        case Types.BOOLEAN:
            return TrueMemory.valueOf(set.getBoolean(index));
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.DECIMAL:
            return DoubleMemory.valueOf(set.getDouble(index));
        case Types.NULL:
            return Memory.NULL;
        case Types.TIME:
            Time time = set.getTime(index);
            return ObjectMemory.valueOf(new WrapTime(env, time));
        case Types.TIMESTAMP:
            Timestamp timestamp = set.getTimestamp(index);
            return ObjectMemory.valueOf(new WrapTime(env, timestamp));
        case Types.DATE:
            Date date = set.getDate(index);
            return ObjectMemory.valueOf(new WrapTime(env, date));
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.CHAR:
        case Types.BIGINT:
            return StringMemory.valueOf(set.getString(index));
        case Types.NVARCHAR:
        case Types.LONGNVARCHAR:
            return StringMemory.valueOf(set.getNString(index));
        case Types.BINARY:
            return new BinaryMemory(set.getBytes(index));
        case Types.BLOB:
        case Types.CLOB:
        case Types.NCLOB:
            try {
                Blob blob = set.getBlob(index);
                return ObjectMemory.valueOf(new MiscStream(env, blob.getBinaryStream()));
            } catch (SQLException e) {
                return new BinaryMemory(set.getBytes(index));
            }
        default:
            return StringMemory.valueOf(set.getString(index));
    }
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) WrapTime(php.runtime.ext.core.classes.time.WrapTime) MiscStream(php.runtime.ext.core.classes.stream.MiscStream)

Aggregations

WrapTime (php.runtime.ext.core.classes.time.WrapTime)5 Signature (php.runtime.annotation.Reflection.Signature)2 InputStream (java.io.InputStream)1 Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 LocalTime (java.time.LocalTime)1 Getter (php.runtime.annotation.Reflection.Getter)1 MiscStream (php.runtime.ext.core.classes.stream.MiscStream)1 Stream (php.runtime.ext.core.classes.stream.Stream)1 BinaryMemory (php.runtime.memory.BinaryMemory)1