Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jruby-1_7'
Conflicts:
	core/src/main/java/org/jruby/RubyTime.java
  • Loading branch information
enebo committed Jan 7, 2015
2 parents fe7f9c7 + dbf58e6 commit 422d460
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 46 deletions.
71 changes: 28 additions & 43 deletions core/src/main/java/org/jruby/RubyTime.java
Expand Up @@ -66,6 +66,7 @@
import org.jruby.util.ByteList;
import org.jruby.util.RubyDateFormatter;
import org.jruby.runtime.Helpers;
import org.jruby.util.TypeConverter;

import static org.jruby.RubyComparable.invcmp;
import static org.jruby.runtime.Helpers.invokedynamic;
Expand Down Expand Up @@ -243,49 +244,32 @@ public static DateTimeZone getTimeZoneFromUtcOffset(Ruby runtime, IRubyObject ut
return dtz;
}

/* time.c num_exact
*/
// mri: time.c num_exact
private static IRubyObject numExact(Ruby runtime, IRubyObject v) {
IRubyObject tmp;
switch(v.getMetaClass().getRealClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
return v;
case RATIONAL:
break;
case STRING:
case NIL:
exactTypeError(runtime, v);
default:
if (v instanceof RubyFixnum || v instanceof RubyBignum) return v;
if (v.isNil()) exactTypeError(runtime, v);
if (!(v instanceof RubyRational)) { // Default unknown
if (v.respondsTo("to_r")) {
tmp = v.callMethod(runtime.getCurrentContext(), "to_r");
if(!tmp.eql(UNDEF)) {
if(v.respondsTo("to_str")) {
exactTypeError(runtime, v);
}
v = tmp;
break;
}

tmp = v.callMethod(runtime.getCurrentContext(), "to_int");
if(!tmp.isNil()) {
v = tmp;
break;
}
exactTypeError(runtime, v);
// WTF is this condition for? It responds to to_r and makes something which thinks it is a String?
if (tmp != null && v.respondsTo("to_str")) exactTypeError(runtime, v);
} else {
tmp = TypeConverter.checkIntegerType(runtime, v, "to_int");
if (tmp.isNil()) exactTypeError(runtime, v);
}
v = tmp;
}

switch(v.getMetaClass().getRealClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
return v;
case RATIONAL:
RubyRational r = (RubyRational)v;
if(r.denominator(runtime.getCurrentContext()) == RubyFixnum.newFixnum(runtime, 1)) {
return r.numerator(runtime.getCurrentContext());
}
break;
default:
exactTypeError(runtime, v);
if (v instanceof RubyFixnum || v instanceof RubyBignum) {
return v;
} else if (v instanceof RubyRational) {
RubyRational r = (RubyRational) v;
if (r.denominator(runtime.getCurrentContext()) == RubyFixnum.newFixnum(runtime, 1)) {
return r.numerator(runtime.getCurrentContext());
}
} else {
exactTypeError(runtime, v);
}

return v;
Expand Down Expand Up @@ -731,8 +715,8 @@ private IRubyObject inspectCommon(DateTimeFormatter formatter, DateTimeFormatter
@JRubyMethod
@Override
public RubyArray to_a() {
return getRuntime().newArrayNoCopy(new IRubyObject[] { sec(), min(), hour(), mday(), month(),
year(), wday(), yday(), isdst(), zone() });
return getRuntime().newArrayNoCopy(new IRubyObject[]{sec(), min(), hour(), mday(), month(),
year(), wday(), yday(), isdst(), zone()});
}

@JRubyMethod
Expand Down Expand Up @@ -810,7 +794,7 @@ public RubyInteger year() {

@JRubyMethod
public RubyInteger wday() {
return getRuntime().newFixnum((dt.getDayOfWeek()%7));
return getRuntime().newFixnum((dt.getDayOfWeek() % 7));
}

@JRubyMethod
Expand All @@ -832,7 +816,8 @@ public IRubyObject subsec() {
@JRubyMethod(name = {"gmt_offset", "gmtoff", "utc_offset"})
public RubyInteger gmt_offset() {
int offset = dt.getZone().getOffset(dt.getMillis());
return getRuntime().newFixnum(offset/1000);

return getRuntime().newFixnum(offset / 1000);
}

@JRubyMethod(name = {"isdst", "dst?"})
Expand Down Expand Up @@ -998,7 +983,7 @@ public RubyTime round(ThreadContext context, IRubyObject[] args) {
public static IRubyObject s_new(IRubyObject recv, IRubyObject[] args, Block block) {
Ruby runtime = recv.getRuntime();
RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(getLocalTimeZone(runtime)));
time.callInit(args,block);
time.callInit(args, block);
return time;
}

Expand Down
4 changes: 1 addition & 3 deletions spec/tags/ruby/core/time/getlocal_tags.txt
@@ -1,8 +1,6 @@
fails:Time#getlocal returns a Time with UTC offset specified as an Integer number of seconds
fails:Time#getlocal returns a Time with a UTC offset of the specified number of Rational seconds
fails:Time#getlocal raises ArgumentError if the String argument is not in an ASCII-compatible encoding
fails:Time#getlocal raises ArgumentError if the argument represents a value less than or equal to -86400 seconds
fails:Time#getlocal raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds
fails:Time#getlocal with an argument that responds to #to_int coerces using #to_int
fails:Time#getlocal with an argument that responds to #to_r coerces using #to_r
fails:Time#getlocal with an argument that responds to #to_str coerces using #to_str
fails:Time#getlocal raises ArgumentError if the String argument is not in an ASCII-compatible encoding

0 comments on commit 422d460

Please sign in to comment.