Esempio n. 1
0
  public RubyObject mdump() {
    RubyTime obj = this;
    DateTime dateTime = obj.dt.toDateTime(DateTimeZone.UTC);
    byte dumpValue[] = new byte[8];

    int pe =
        0x1 << 31
            | ((obj.gmt().isTrue()) ? 0x1 : 0x0) << 30
            | (dateTime.getYear() - 1900) << 14
            | (dateTime.getMonthOfYear() - 1) << 10
            | dateTime.getDayOfMonth() << 5
            | dateTime.getHourOfDay();
    int se =
        dateTime.getMinuteOfHour() << 26
            | dateTime.getSecondOfMinute() << 20
            | (dateTime.getMillisOfSecond() * 1000 + (int) usec); // dump usec, not msec

    for (int i = 0; i < 4; i++) {
      dumpValue[i] = (byte) (pe & 0xFF);
      pe >>>= 8;
    }
    for (int i = 4; i < 8; i++) {
      dumpValue[i] = (byte) (se & 0xFF);
      se >>>= 8;
    }
    return RubyString.newString(obj.getRuntime(), new ByteList(dumpValue));
  }
 private DateTime truncateAndUTC(final DateTime input) {
   if (input == null) {
     return null;
   }
   final DateTime result = input.minus(input.getMillisOfSecond());
   return result.toDateTime(DateTimeZone.UTC);
 }
Esempio n. 3
0
 @JRubyMethod(name = "subsec", compat = CompatVersion.RUBY1_9)
 public RubyRational subsec() {
   // TODO: nanosecond resolution (JSR310?)
   return getRuntime().newRational(dt.getMillisOfSecond(), 1000);
 }
Esempio n. 4
0
 @JRubyMethod(name = {"usec", "tv_usec"})
 public RubyInteger usec() {
   return getRuntime().newFixnum(dt.getMillisOfSecond() * 1000 + getUSec());
 }