Skip to content

Commit

Permalink
Showing 28 changed files with 3,685 additions and 1,739 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -5251,6 +5251,8 @@ protected TypePopulator computeValue(Class<?> type) {
// I know of use very few of them. Even if there are many the size of these lists are modest.
private final Map<String, List<StrptimeToken>> strptimeFormatCache = new ConcurrentHashMap<>();

transient RubyString tzVar;

@Deprecated
private void setNetworkStack() {
deprecatedNetworkStackProperty();
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -345,8 +345,8 @@ private final void alloc() {
{ head.prevAdded = head.nextAdded = head; }

public static final class RubyHashEntry implements Map.Entry {
private IRubyObject key;
private IRubyObject value;
IRubyObject key;
IRubyObject value;
private RubyHashEntry next;
private RubyHashEntry prevAdded;
private RubyHashEntry nextAdded;
@@ -580,6 +580,10 @@ protected RubyHashEntry internalGetEntry(IRubyObject key) {
return NO_ENTRY;
}

final RubyHashEntry getEntry(IRubyObject key) {
return internalGetEntry(key);
}

private boolean internalKeyExist(RubyHashEntry entry, int hash, IRubyObject key) {
return (entry.hash == hash
&& (entry.key == key || (!isComparedByIdentity() && key.eql(entry.key))));
21 changes: 15 additions & 6 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -179,20 +179,29 @@ public static int num2int(IRubyObject arg) {
/** check_int
*
*/
public static int checkInt(final Ruby runtime, long num){
if (num < Integer.MIN_VALUE) {
tooSmall(runtime, num);
} else if (num > Integer.MAX_VALUE) {
tooBig(runtime, num);
}
return (int) num;
}

public static void checkInt(IRubyObject arg, long num){
if (num < Integer.MIN_VALUE) {
tooSmall(arg, num);
tooSmall(arg.getRuntime(), num);
} else if (num > Integer.MAX_VALUE) {
tooBig(arg, num);
tooBig(arg.getRuntime(), num);
}
}

private static void tooSmall(IRubyObject arg, long num) {
throw arg.getRuntime().newRangeError("integer " + num + " too small to convert to `int'");
private static void tooSmall(Ruby runtime, long num) {
throw runtime.newRangeError("integer " + num + " too small to convert to `int'");
}

private static void tooBig(IRubyObject arg, long num) {
throw arg.getRuntime().newRangeError("integer " + num + " too big to convert to `int'");
private static void tooBig(Ruby runtime, long num) {
throw runtime.newRangeError("integer " + num + " too big to convert to `int'");
}

/**
41 changes: 24 additions & 17 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -53,7 +53,6 @@
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.JavaSites.TimeSites;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
@@ -66,11 +65,9 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
@@ -136,23 +133,32 @@ public ClassIndex getNativeClassIndex() {
return ClassIndex.TIME;
}

private static IRubyObject getEnvTimeZone(Ruby runtime) {
RubyString tzVar = (RubyString) runtime.getTime().getInternalVariable("tz_string");
if (tzVar == null) {
tzVar = runtime.newString(TZ_STRING);
tzVar.setFrozen(true);
runtime.getTime().setInternalVariable("tz_string", tzVar);
private static transient Object[] tzValue; // (RubyString, String) - assuming single runtime or same ENV['TZ']

public static String getEnvTimeZone(Ruby runtime) {
RubyString tz = runtime.tzVar;
if (tz == null) {
tz = runtime.newString(TZ_STRING);
tz.setFrozen(true);
runtime.tzVar = tz;
}
return runtime.getENV().op_aref(runtime.getCurrentContext(), tzVar);

RubyHash.RubyHashEntry entry = runtime.getENV().getEntry(tz);
if (entry.key == null || entry.key == NEVER) return null; // NO_ENTRY

if (entry.key != tz) runtime.tzVar = (RubyString) entry.key;

Object[] tzVal = tzValue;
if (tzVal != null && tzVal[0] == entry.value) return (String) tzVal[1]; // cache RubyString -> String

final String val = (entry.value instanceof RubyString) ? ((RubyString) entry.value).asJavaString() : null;
tzValue = new Object[] { entry.value, val };
return val;
}

public static DateTimeZone getLocalTimeZone(Ruby runtime) {
IRubyObject tz = getEnvTimeZone(runtime);

if (tz == null || ! (tz instanceof RubyString)) {
return DateTimeZone.getDefault();
}
return getTimeZoneFromTZString(runtime, tz.toString());
final String tz = getEnvTimeZone(runtime);
return tz == null ? DateTimeZone.getDefault() : getTimeZoneFromTZString(runtime, tz);
}

public static DateTimeZone getTimeZoneFromTZString(Ruby runtime, String zone) {
@@ -918,7 +924,8 @@ public IRubyObject zone() {
}

public static String getRubyTimeZoneName(Ruby runtime, DateTime dt) {
return RubyTime.getRubyTimeZoneName(getEnvTimeZone(runtime).toString(), dt);
final String tz = getEnvTimeZone(runtime);
return RubyTime.getRubyTimeZoneName(tz == null ? "" : tz, dt);
}

public static String getRubyTimeZoneName(String envTZ, DateTime dt) {
14 changes: 9 additions & 5 deletions core/src/main/java/org/jruby/ext/date/DateLibrary.java
Original file line number Diff line number Diff line change
@@ -6,12 +6,16 @@

import java.io.IOException;

/**
* Assumes kernel will lo
*/
public class DateLibrary implements Library {

public static void load(Ruby runtime) {
RubyClass Date = RubyDate.createDateClass(runtime);
RubyDateTime.createDateTimeClass(runtime, Date);
TimeExt.load(runtime);
}

public void load(final Ruby runtime, boolean wrap) throws IOException {
RubyClass dateClass = runtime.getClass("Date");
dateClass.defineAnnotatedMethods(RubyDate.class);
DateLibrary.load(runtime);
}

}
Loading

0 comments on commit cf89614

Please sign in to comment.