Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b975c7af0566
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d69dc0984f41
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Mar 9, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3a496c4 View commit details

Commits on Mar 20, 2018

  1. Merge pull request #5056 from ChrisBr/ruby25/time#at

    Time#at receives 3rd argument which specifies the unit of 2nd argument
    kares authored Mar 20, 2018
    Copy the full SHA
    d69dc09 View commit details
Showing with 42 additions and 8 deletions.
  1. +42 −8 core/src/main/java/org/jruby/RubyTime.java
50 changes: 42 additions & 8 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -1184,6 +1184,12 @@ public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObjec

@JRubyMethod(meta = true)
public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObject arg1, IRubyObject arg2) {
RubySymbol ms = context.runtime.newSymbol("microsecond");
return at(context, recv, arg1, arg2, ms);
}

@JRubyMethod(meta = true)
public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3) {
Ruby runtime = context.runtime;

RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(0L, getLocalTimeZone(runtime)));
@@ -1201,16 +1207,44 @@ public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObjec
millisecs = RubyNumeric.num2long(arg1) * 1000;
}

if (!(arg3 instanceof RubySymbol)) {
throw context.runtime.newArgumentError("unexpected unit " + arg3);
}

RubySymbol unit = (RubySymbol) arg3;

if (arg2 instanceof RubyFloat || arg2 instanceof RubyRational) {
double micros = RubyNumeric.num2dbl(arg2);
double nanos = micros * 1000;
millisecs += (long) (nanos / 1000000);
nanosecs += (long) (nanos % 1000000);
if (runtime.newSymbol("microsecond").eql(unit) || runtime.newSymbol("usec").eql(unit)) {
double micros = RubyNumeric.num2dbl(arg2);
double nanos = micros * 1000;
millisecs += (long) (nanos / 1000000);
nanosecs += (long) (nanos % 1000000);
} else if (runtime.newSymbol("millisecond").eql(unit)) {
double millis = RubyNumeric.num2dbl(arg2);
double nanos = millis * 1000000;
millisecs += (long) (nanos / 1000000);
nanosecs += (long) (nanos % 1000000);
} else if (runtime.newSymbol("nanosecond").eql(unit) || runtime.newSymbol("nsec").eql(unit)) {
nanosecs += RubyNumeric.num2long(arg2);
} else {
throw context.runtime.newArgumentError("unexpected unit " + arg3);
}
} else {
long micros = RubyNumeric.num2long(arg2);
long nanos = micros * 1000;
millisecs += nanos / 1000000;
nanosecs += nanos % 1000000;
if (runtime.newSymbol("microsecond").eql(unit) || runtime.newSymbol("usec").eql(unit)) {
long micros = RubyNumeric.num2long(arg2);
long nanos = micros * 1000;
millisecs += nanos / 1000000;
nanosecs += nanos % 1000000;
} else if (runtime.newSymbol("millisecond").eql(unit)) {
double millis = RubyNumeric.num2long(arg2);
double nanos = millis * 1000000;
millisecs += nanos / 1000000;
nanosecs += nanos % 1000000;
} else if (runtime.newSymbol("nanosecond").eql(unit) || runtime.newSymbol("nsec").eql(unit)) {
nanosecs += RubyNumeric.num2long(arg2);
} else {
throw context.runtime.newArgumentError("unexpected unit " + arg3);
}
}

long nanosecOverflow = (nanosecs / 1000000);