Skip to content

Commit

Permalink
Fixes #4227. Missing unit :second for Process.clock_gettime
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Nov 7, 2016
1 parent bc7036a commit c7e1459
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/RubyProcess.java
Expand Up @@ -129,6 +129,7 @@ public static RubyModule createProcessModule(Ruby runtime) {
public static final String CLOCK_UNIT_NANOSECOND = "nanosecond";
public static final String CLOCK_UNIT_MICROSECOND = "microsecond";
public static final String CLOCK_UNIT_MILLISECOND = "millisecond";
public static final String CLOCK_UNIT_SECOND = "second";
public static final String CLOCK_UNIT_FLOAT_MICROSECOND = "float_microsecond";
public static final String CLOCK_UNIT_FLOAT_MILLISECOND = "float_millisecond";
public static final String CLOCK_UNIT_FLOAT_SECOND = "float_second";
Expand Down Expand Up @@ -1426,7 +1427,7 @@ public static IRubyObject clock_gettime(ThreadContext context, IRubyObject self,
public static IRubyObject clock_gettime(ThreadContext context, IRubyObject self, IRubyObject _clock_id, IRubyObject _unit) {
Ruby runtime = context.runtime;

if (!(_unit instanceof RubySymbol)) {
if (!(_unit instanceof RubySymbol) && !_unit.isNil()) {
throw runtime.newArgumentError("unexpected unit: " + _unit);
}

Expand Down Expand Up @@ -1487,11 +1488,13 @@ private static IRubyObject makeClockResult(Ruby runtime, long nanos, String unit
return runtime.newFixnum(nanos / 1000);
} else if (unit.equals(CLOCK_UNIT_MILLISECOND)) {
return runtime.newFixnum(nanos / 1000000);
} else if (unit.equals(CLOCK_UNIT_SECOND)) {
return runtime.newFixnum(nanos / 1000000000);
} else if (unit.equals(CLOCK_UNIT_FLOAT_MICROSECOND)) {
return runtime.newFloat(nanos / 1000.0);
} else if (unit.equals(CLOCK_UNIT_FLOAT_MILLISECOND)) {
return runtime.newFloat(nanos / 1000000.0);
} else if (unit.equals(CLOCK_UNIT_FLOAT_SECOND)) {
} else if (unit.equals(CLOCK_UNIT_FLOAT_SECOND) || unit.equals("")) {
return runtime.newFloat(nanos / 1000000000.0);
} else {
throw runtime.newArgumentError("unexpected unit: " + unit);
Expand All @@ -1511,7 +1514,7 @@ public static IRubyObject clock_getres(ThreadContext context, IRubyObject self,
public static IRubyObject clock_getres(ThreadContext context, IRubyObject self, IRubyObject _clock_id, IRubyObject _unit) {
Ruby runtime = context.runtime;

if (!(_unit instanceof RubySymbol)) {
if (!(_unit instanceof RubySymbol) && !_unit.isNil()) {
throw runtime.newArgumentError("unexpected unit: " + _unit);
}

Expand Down
1 change: 0 additions & 1 deletion test/mri/excludes/TestProcess.rb
Expand Up @@ -7,7 +7,6 @@
exclude :test_clock_gettime_CLOCK_BASED_CLOCK_PROCESS_CPUTIME_ID, "missing process timing functionality"
exclude :test_clock_gettime_GETTIMEOFDAY_BASED_CLOCK_REALTIME, "missing process timing functionality"
exclude :test_clock_gettime_TIME_BASED_CLOCK_REALTIME, "missing process timing functionality"
exclude :test_clock_gettime_unit, "missing process timing functionality"
exclude :test_deadlock_by_signal_at_forking, "uses fork"
exclude :test_exec_noshell, "needs investigation"
exclude :test_exec_wordsplit, "needs investigation"
Expand Down

0 comments on commit c7e1459

Please sign in to comment.