Example #1
0
 @TruffleBoundary
 private DateTime localtime(long milliseconds, RubyString timeZone) {
   return new DateTime(
       milliseconds,
       org.jruby.RubyTime.getTimeZoneFromTZString(
           getContext().getRuntime(), timeZone.toString()));
 }
Example #2
0
    private RubyTime buildTime(
        VirtualFrame frame,
        RubyClass timeClass,
        int sec,
        int min,
        int hour,
        int mday,
        int month,
        int year,
        int nsec,
        int isdst,
        boolean fromutc,
        Object utcoffset) {
      CompilerDirectives.transferToInterpreter();

      if (sec < 0
          || sec > 59
          || min < 0
          || min > 59
          || hour < 0
          || hour > 23
          || mday < 1
          || mday > 31
          || month < 1
          || month > 12) {
        throw new RaiseException(getContext().getCoreLibrary().argumentErrorOutOfRange(this));
      }

      final DateTimeZone zone;
      if (fromutc) {
        zone = DateTimeZone.UTC;
      } else if (utcoffset == nil()) {
        String tz = readTimeZoneNode.executeRubyString(frame).toString();
        zone = org.jruby.RubyTime.getTimeZoneFromTZString(getContext().getRuntime(), tz);
      } else if (utcoffset instanceof Integer) {
        zone = DateTimeZone.forOffsetMillis(((int) utcoffset) * 1_000);
      } else if (utcoffset instanceof Long) {
        zone = DateTimeZone.forOffsetMillis((int) ((long) utcoffset) * 1_000);
      } else if (utcoffset instanceof RubyBasicObject) {
        final int millis = cast(ruby(frame, "(offset * 1000).to_i", "offset", utcoffset));
        zone = DateTimeZone.forOffsetMillis(millis);
      } else {
        throw new UnsupportedOperationException(
            String.format("%s %s %s %s", isdst, fromutc, utcoffset, utcoffset.getClass()));
      }

      if (isdst == -1) {
        final DateTime dateTime =
            new DateTime(year, month, mday, hour, min, sec, nsec / 1_000_000, zone);
        return new RubyTime(timeClass, dateTime, utcoffset);
      } else {
        throw new UnsupportedOperationException(
            String.format("%s %s %s %s", isdst, fromutc, utcoffset, utcoffset.getClass()));
      }
    }
Example #3
0
 @TruffleBoundary
 private DateTime now(RubyString timeZone) {
   return DateTime.now(
       org.jruby.RubyTime.getTimeZoneFromTZString(
           getContext().getRuntime(), timeZone.toString()));
 }