Skip to content

Commit 422d460

Browse files
committed
Merge branch 'jruby-1_7'
Conflicts: core/src/main/java/org/jruby/RubyTime.java
2 parents fe7f9c7 + dbf58e6 commit 422d460

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

core/src/main/java/org/jruby/RubyTime.java

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.jruby.util.ByteList;
6767
import org.jruby.util.RubyDateFormatter;
6868
import org.jruby.runtime.Helpers;
69+
import org.jruby.util.TypeConverter;
6970

7071
import static org.jruby.RubyComparable.invcmp;
7172
import static org.jruby.runtime.Helpers.invokedynamic;
@@ -243,49 +244,32 @@ public static DateTimeZone getTimeZoneFromUtcOffset(Ruby runtime, IRubyObject ut
243244
return dtz;
244245
}
245246

246-
/* time.c num_exact
247-
*/
247+
// mri: time.c num_exact
248248
private static IRubyObject numExact(Ruby runtime, IRubyObject v) {
249249
IRubyObject tmp;
250-
switch(v.getMetaClass().getRealClass().getClassIndex()) {
251-
case FIXNUM:
252-
case BIGNUM:
253-
return v;
254-
case RATIONAL:
255-
break;
256-
case STRING:
257-
case NIL:
258-
exactTypeError(runtime, v);
259-
default:
250+
if (v instanceof RubyFixnum || v instanceof RubyBignum) return v;
251+
if (v.isNil()) exactTypeError(runtime, v);
252+
if (!(v instanceof RubyRational)) { // Default unknown
253+
if (v.respondsTo("to_r")) {
260254
tmp = v.callMethod(runtime.getCurrentContext(), "to_r");
261-
if(!tmp.eql(UNDEF)) {
262-
if(v.respondsTo("to_str")) {
263-
exactTypeError(runtime, v);
264-
}
265-
v = tmp;
266-
break;
267-
}
268-
269-
tmp = v.callMethod(runtime.getCurrentContext(), "to_int");
270-
if(!tmp.isNil()) {
271-
v = tmp;
272-
break;
273-
}
274-
exactTypeError(runtime, v);
255+
// WTF is this condition for? It responds to to_r and makes something which thinks it is a String?
256+
if (tmp != null && v.respondsTo("to_str")) exactTypeError(runtime, v);
257+
} else {
258+
tmp = TypeConverter.checkIntegerType(runtime, v, "to_int");
259+
if (tmp.isNil()) exactTypeError(runtime, v);
260+
}
261+
v = tmp;
275262
}
276263

277-
switch(v.getMetaClass().getRealClass().getClassIndex()) {
278-
case FIXNUM:
279-
case BIGNUM:
280-
return v;
281-
case RATIONAL:
282-
RubyRational r = (RubyRational)v;
283-
if(r.denominator(runtime.getCurrentContext()) == RubyFixnum.newFixnum(runtime, 1)) {
284-
return r.numerator(runtime.getCurrentContext());
285-
}
286-
break;
287-
default:
288-
exactTypeError(runtime, v);
264+
if (v instanceof RubyFixnum || v instanceof RubyBignum) {
265+
return v;
266+
} else if (v instanceof RubyRational) {
267+
RubyRational r = (RubyRational) v;
268+
if (r.denominator(runtime.getCurrentContext()) == RubyFixnum.newFixnum(runtime, 1)) {
269+
return r.numerator(runtime.getCurrentContext());
270+
}
271+
} else {
272+
exactTypeError(runtime, v);
289273
}
290274

291275
return v;
@@ -731,8 +715,8 @@ private IRubyObject inspectCommon(DateTimeFormatter formatter, DateTimeFormatter
731715
@JRubyMethod
732716
@Override
733717
public RubyArray to_a() {
734-
return getRuntime().newArrayNoCopy(new IRubyObject[] { sec(), min(), hour(), mday(), month(),
735-
year(), wday(), yday(), isdst(), zone() });
718+
return getRuntime().newArrayNoCopy(new IRubyObject[]{sec(), min(), hour(), mday(), month(),
719+
year(), wday(), yday(), isdst(), zone()});
736720
}
737721

738722
@JRubyMethod
@@ -810,7 +794,7 @@ public RubyInteger year() {
810794

811795
@JRubyMethod
812796
public RubyInteger wday() {
813-
return getRuntime().newFixnum((dt.getDayOfWeek()%7));
797+
return getRuntime().newFixnum((dt.getDayOfWeek() % 7));
814798
}
815799

816800
@JRubyMethod
@@ -832,7 +816,8 @@ public IRubyObject subsec() {
832816
@JRubyMethod(name = {"gmt_offset", "gmtoff", "utc_offset"})
833817
public RubyInteger gmt_offset() {
834818
int offset = dt.getZone().getOffset(dt.getMillis());
835-
return getRuntime().newFixnum(offset/1000);
819+
820+
return getRuntime().newFixnum(offset / 1000);
836821
}
837822

838823
@JRubyMethod(name = {"isdst", "dst?"})
@@ -998,7 +983,7 @@ public RubyTime round(ThreadContext context, IRubyObject[] args) {
998983
public static IRubyObject s_new(IRubyObject recv, IRubyObject[] args, Block block) {
999984
Ruby runtime = recv.getRuntime();
1000985
RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(getLocalTimeZone(runtime)));
1001-
time.callInit(args,block);
986+
time.callInit(args, block);
1002987
return time;
1003988
}
1004989

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
fails:Time#getlocal returns a Time with UTC offset specified as an Integer number of seconds
21
fails:Time#getlocal returns a Time with a UTC offset of the specified number of Rational seconds
2+
fails:Time#getlocal raises ArgumentError if the String argument is not in an ASCII-compatible encoding
33
fails:Time#getlocal raises ArgumentError if the argument represents a value less than or equal to -86400 seconds
44
fails:Time#getlocal raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds
5-
fails:Time#getlocal with an argument that responds to #to_int coerces using #to_int
65
fails:Time#getlocal with an argument that responds to #to_r coerces using #to_r
76
fails:Time#getlocal with an argument that responds to #to_str coerces using #to_str
8-
fails:Time#getlocal raises ArgumentError if the String argument is not in an ASCII-compatible encoding

0 commit comments

Comments
 (0)