Package org.jruby

Examples of org.jruby.RubyTime


            case Types.TIMESTAMP:
                java.sql.Timestamp ts = rs.getTimestamp(col);
                if (ts == null) {
                    return runtime.getNil();
                }
                RubyTime rbt = prepareRubyTimeFromSqlTime(runtime, sqlTimestampToDateTime(ts));
                long usec = (long) (ts.getNanos() / 1000) % 1000;
                rbt.setUSec(usec);
                return rbt;
            case Types.DATE:
                java.sql.Date da = rs.getDate(col);
                if (da == null) {
                    return runtime.getNil();
View Full Code Here


     * @param time
     * @return
     */
    protected static RubyTime prepareRubyTimeFromSqlTime(Ruby runtime,
            DateTime time) {
        RubyTime rbTime = RubyTime.newTime(runtime, time);
        return rbTime;
    }
View Full Code Here

     * @param date
     * @return
     */
    protected static RubyTime prepareRubyTimeFromSqlDate(Ruby runtime,
            Date date) {
        RubyTime rbTime = RubyTime.newTime(runtime, date.getTime());
        return rbTime;
    }
View Full Code Here

                    ps.setTimestamp(index, new java.sql.Timestamp(dd.getTime()), Calendar.getInstance());
                } catch(Exception e) {
                    ps.setString(index, RubyString.objAsString(context, value).toString());
                }
            } else {
                RubyTime rubyTime = (RubyTime) value;
                java.util.Date date = rubyTime.getJavaDate();
                long millis = date.getTime();
                long micros = rubyTime.microseconds() - millis / 1000;
                java.sql.Timestamp ts = new java.sql.Timestamp(millis);
                java.util.Calendar cal = Calendar.getInstance();
                cal.setTime(date);
                ts.setNanos((int)(micros * 1000));
                ps.setTimestamp(index, ts, cal);
View Full Code Here

    @JRubyMethod
    public IRubyObject gc_storage(ThreadContext context, IRubyObject arg) {
        if (!(arg.respondsTo("to_time"))) {
            throw context.getRuntime().newArgumentError("Wrong argument type");
        }
        RubyTime rubyTime = (RubyTime) RuntimeHelpers.invoke(context, arg, "to_time");
        Date olderThan = rubyTime.getJavaDate();
        try {
            DiametricService.getFn("datomic.api", "gc-strage").invoke(conn, olderThan);
        } catch (Throwable t) {
            throw context.getRuntime().newRuntimeError("Datomic error: " + t.getMessage());
        }
View Full Code Here

            java.math.BigInteger bivalue = new java.math.BigInteger((String)svalue.toJava(String.class));
            return (Object)bivalue;
        }
        if (value instanceof RubyFloat) return (Object)((RubyFloat)value).toJava(Double.class);
        if (value instanceof RubyTime) {
            RubyTime tmvalue = (RubyTime)value;
            return (Object)tmvalue.getJavaDate();
        }
        if (value instanceof RubySymbol) {
            // schema or data keyword
            RubyString edn_string = (RubyString)RuntimeHelpers.invoke(context, value, "to_s");
            return (Object)Keyword.intern((String)edn_string.asJavaString());
        }
        if (value.respondsTo("to_edn") && value.respondsTo("symbol")) {
            // EDN::Type::Symbol (query)
            RubyString edn_string = (RubyString)RuntimeHelpers.invoke(context, value, "to_edn");
            return (Object)clojure.lang.Symbol.intern((String)edn_string.asJavaString());
        }
        if (value.respondsTo("to_time")) {
            // DateTime or Date
            RubyTime tmvalue = (RubyTime)RuntimeHelpers.invoke(context, value, "to_time");
            return (Object)tmvalue.getJavaDate();
        }
        // needs to check Set since Set responses to "to_a"
        if (value.respondsTo("intersection")) {
            return getPersistentSet(context, value);
        }
View Full Code Here

        final IRubyObject column, final int type) throws SQLException {
        if ( value.isNil() ) statement.setNull(index, Types.TIMESTAMP);
        else {
            value = DateTimeUtils.getTimeInDefaultTimeZone(context, value);
            if ( value instanceof RubyTime ) {
                final RubyTime timeValue = (RubyTime) value;
                final DateTime dateTime = timeValue.getDateTime();

                final Timestamp timestamp = new Timestamp( dateTime.getMillis() );
                if ( type != Types.DATE ) { // 1942-11-30T01:02:03.123_456
                    // getMillis already set nanos to: 123_000_000
                    final int usec = (int) timeValue.getUSec(); // 456 on JRuby
                    if ( usec >= 0 ) {
                        timestamp.setNanos( timestamp.getNanos() + usec * 1000 );
                    }
                }
                statement.setTimestamp( index, timestamp, getTimeZoneCalendar(dateTime.getZone().getID()) );
View Full Code Here

        final IRubyObject column, final int type) throws SQLException {
        if ( value.isNil() ) statement.setNull(index, Types.TIME);
        else {
            value = getTimeInDefaultTimeZone(context, value);
            if ( value instanceof RubyTime ) {
                final RubyTime timeValue = (RubyTime) value;
                final DateTime dateTime = timeValue.getDateTime();

                final Time time = new Time( dateTime.getMillis() );
                statement.setTime( index, time, getTimeZoneCalendar(dateTime.getZone().getID()) );
            }
            else if ( value instanceof RubyString ) {
                final Time time = Time.valueOf( value.toString() );
                statement.setTime( index, time ); // assume local time-zone
            }
            else { // DateTime ( ActiveSupport::TimeWithZone.to_time )
                final RubyFloat timeValue = value.convertToFloat(); // to_f
                final Time time = new Time(timeValue.getLongValue() * 1000); // millis
                // java.sql.Time is expected to be only up to second precision
                statement.setTime( index, time, getTimeZoneCalendar("GMT") );
            }
        }
    }
View Full Code Here

                    ps.setTimestamp(index, new java.sql.Timestamp(dd.getTime()), Calendar.getInstance());
                } catch(Exception e) {
                    ps.setString(index, RubyString.objAsString(value).toString());
                }
            } else {
                RubyTime rubyTime = (RubyTime) value;
                java.util.Date date = rubyTime.getJavaDate();
                long millis = date.getTime();
                long micros = rubyTime.microseconds() - millis / 1000;
                java.sql.Timestamp ts = new java.sql.Timestamp(millis);
                java.util.Calendar cal = Calendar.getInstance();
                cal.setTime(date);
                ts.setNanos((int)(micros * 1000));
                ps.setTimestamp(index, ts, cal);
View Full Code Here

TOP

Related Classes of org.jruby.RubyTime

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.