Example #1
0
 @Specialization
 public RubyTime timeSDup(RubyTime other) {
   final RubyTime time =
       new RubyTime(
           getContext().getCoreLibrary().getTimeClass(), other.getDateTime(), other.getOffset());
   return time;
 }
Example #2
0
 @Specialization
 public Object timeUTCOffset(RubyTime time) {
   Object offset = time.getOffset();
   if (offset != nil()) {
     return offset;
   } else {
     return time.getDateTime().getZone().getOffset(time.getDateTime().getMillis()) / 1_000;
   }
 }
Example #3
0
    @Specialization
    public RubyBasicObject timeDecompose(VirtualFrame frame, RubyTime time) {
      CompilerDirectives.transferToInterpreter();
      final DateTime dateTime = time.getDateTime();
      final int sec = dateTime.getSecondOfMinute();
      final int min = dateTime.getMinuteOfHour();
      final int hour = dateTime.getHourOfDay();
      final int day = dateTime.getDayOfMonth();
      final int month = dateTime.getMonthOfYear();
      final int year = dateTime.getYear();

      int wday = dateTime.getDayOfWeek();

      if (wday == 7) {
        wday = 0;
      }

      final int yday = dateTime.getDayOfYear();
      final boolean isdst = false;

      final String envTimeZoneString = readTimeZoneNode.executeRubyString(frame).toString();
      String zoneString = org.jruby.RubyTime.zoneHelper(envTimeZoneString, dateTime, false);
      Object zone;
      if (zoneString.matches(".*-\\d+")) {
        zone = nil();
      } else {
        zone = createString(zoneString);
      }

      final Object[] decomposed =
          new Object[] {sec, min, hour, day, month, year, wday, yday, isdst, zone};
      return createArray(decomposed, decomposed.length);
    }
Example #4
0
 @TruffleBoundary
 @Specialization
 public RubyBasicObject timeStrftime(RubyTime time, RubyString format) {
   final RubyDateFormatter rdf =
       getContext().getRuntime().getCurrentContext().getRubyDateFormatter();
   // TODO CS 15-Feb-15 ok to just pass nanoseconds as 0?
   return createString(
       rdf.formatToByteList(
           rdf.compilePattern(StringNodes.getByteList(format), false),
           time.getDateTime(),
           0,
           null));
 }
Example #5
0
 @Specialization
 public long timeSetNSeconds(RubyTime time, int nanoseconds) {
   time.setDateTime(time.getDateTime().withMillisOfSecond(nanoseconds / 1_000_000));
   return nanoseconds;
 }
Example #6
0
 @Specialization
 public long timeNSeconds(RubyTime time) {
   return time.getDateTime().getMillisOfSecond() * 1_000_000L;
 }
Example #7
0
 @Specialization
 public long timeSeconds(RubyTime time) {
   return time.getDateTime().getMillis() / 1_000;
 }