Example #1
0
    public static IRubyObject prepareRubyDateTimeFromSqlTimestamp(Ruby runtime,Timestamp stamp){

       if (stamp.getTime() == 0) {
           return runtime.getNil();
       }

       gregCalendar.setTime(stamp);
       int month = gregCalendar.get(Calendar.MONTH);
       month++; // In Calendar January == 0, etc...

       int zoneOffset = gregCalendar.get(Calendar.ZONE_OFFSET)/3600000;
       RubyClass klazz = runtime.fastGetClass("DateTime");

       IRubyObject rbOffset = runtime.fastGetClass("Rational")
                .callMethod(runtime.getCurrentContext(), "new",new IRubyObject[]{
            runtime.newFixnum(zoneOffset),runtime.newFixnum(24)
        });

       return klazz.callMethod(runtime.getCurrentContext() , "civil",
                 new IRubyObject []{runtime.newFixnum(gregCalendar.get(Calendar.YEAR)),
                 runtime.newFixnum(month),
                 runtime.newFixnum(gregCalendar.get(Calendar.DAY_OF_MONTH)),
                 runtime.newFixnum(gregCalendar.get(Calendar.HOUR_OF_DAY)),
                 runtime.newFixnum(gregCalendar.get(Calendar.MINUTE)),
                 runtime.newFixnum(gregCalendar.get(Calendar.SECOND)),
                 rbOffset});
    }
Example #2
0
  static void createTCPServer(Ruby runtime) {
    RubyClass rb_cTCPServer =
        runtime.defineClass("TCPServer", runtime.fastGetClass("TCPSocket"), TCPSERVER_ALLOCATOR);

    rb_cTCPServer.defineAnnotatedMethods(RubyTCPServer.class);

    runtime.getObject().fastSetConstant("TCPserver", rb_cTCPServer);
  }
Example #3
0
    public static IRubyObject prepareRubyDateFromSqlDate(Ruby runtime,Date date){

       if (date.getTime() == 0) {
           return runtime.getNil();
       }

       gregCalendar.setTime(date);
       int month = gregCalendar.get(Calendar.MONTH);
       month++; // In Calendar January == 0, etc...
       RubyClass klazz = runtime.fastGetClass("Date");
       return klazz.callMethod(
                 runtime.getCurrentContext() ,"civil",
                 new IRubyObject []{ runtime.newFixnum(gregCalendar.get(Calendar.YEAR)),
                 runtime.newFixnum(month),
                 runtime.newFixnum(gregCalendar.get(Calendar.DAY_OF_MONTH))});
    }