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: 4e1f02c813d9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7335e212f637
Choose a head ref
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 20, 2018

  1. Copy the full SHA
    db2a375 View commit details
  2. Copy the full SHA
    65be3cc View commit details
  3. Copy the full SHA
    d12091f View commit details
  4. Copy the full SHA
    670ff64 View commit details
  5. Copy the full SHA
    7335e21 View commit details
8 changes: 3 additions & 5 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -246,11 +246,9 @@ private static RubyNumeric canonicalizeInternalNoReduce(ThreadContext context, R

// MRI: nurat_canonicalize, value check part
private static boolean canonicalizeShouldNegate(ThreadContext context, RubyInteger den) {
final Ruby runtime = context.runtime;
final RubyFixnum zero = RubyFixnum.zero(runtime);
long res = f_cmp(context, den, zero).getLongValue();
if (res == 0) throw runtime.newZeroDivisionError();
return res == -1;
final int signum = den.signum();
if (signum == 0) throw context.runtime.newZeroDivisionError();
return signum < 0;
}

/** nurat_s_new
52 changes: 22 additions & 30 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -88,8 +88,9 @@
@JRubyClass(name="Time", include="Comparable")
public class RubyTime extends RubyObject {
public static final String UTC = "UTC";
public static final BigDecimal ONE_MILLION_BD = BigDecimal.valueOf(1000000);
public static final BigDecimal ONE_BILLION_BD = BigDecimal.valueOf(1000000000);

private static final BigDecimal ONE_MILLION_BD = BigDecimal.valueOf(1000000);
private static final BigDecimal ONE_BILLION_BD = BigDecimal.valueOf(1000000000);

private DateTime dt;
private long nsec;
@@ -113,20 +114,6 @@ public class RubyTime extends RubyObject {

private boolean isTzRelative = false; // true if and only if #new is called with a numeric offset (e.g., "+03:00")

/* Some TZ values need to be overriden for Time#zone
*/
private static final Map<String, String> SHORT_STD_TZNAME = Helpers.map(
"Etc/UCT", "UCT",
"MET", "MET", // needs to be overriden
"UCT", "UCT"
);

private static final Map<String, String> SHORT_DL_TZNAME = Helpers.map(
"Etc/UCT", "UCT",
"MET", "MEST", // needs to be overriden
"UCT", "UCT"
);

private void setIsTzRelative(boolean tzRelative) {
isTzRelative = tzRelative;
}
@@ -929,26 +916,28 @@ public RubyBoolean isdst() {
@JRubyMethod
public IRubyObject zone() {
if (isTzRelative) return getRuntime().getNil();
RubyString zone = getRuntime().newString(RubyTime.getRubyTimeZoneName(getRuntime(), dt));

RubyString zone = getRuntime().newString(getZoneName());
if (zone.isAsciiOnly()) zone.setEncoding(USASCIIEncoding.INSTANCE);

return zone;
}

public String getZoneName() {
return getRubyTimeZoneName(getRuntime(), dt);
}

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

public static String getRubyTimeZoneName(String envTZ, DateTime dt) {
// see declaration of SHORT_TZNAME
if (SHORT_STD_TZNAME.containsKey(envTZ) && ! dt.getZone().toTimeZone().inDaylightTime(dt.toDate())) {
return SHORT_STD_TZNAME.get(envTZ);
}

if (SHORT_DL_TZNAME.containsKey(envTZ) && dt.getZone().toTimeZone().inDaylightTime(dt.toDate())) {
return SHORT_DL_TZNAME.get(envTZ);
switch (envTZ) { // Some TZ values need to be overriden for Time#zone
case "Etc/UCT":
case "UCT":
return "UCT";
case "MET":
return inDaylighTime(dt) ? "MEST" : "MET"; // needs to be overriden
}

String zone = dt.getZone().getShortName(dt.getMillis());
@@ -970,6 +959,10 @@ public static String getRubyTimeZoneName(String envTZ, DateTime dt) {
return zone;
}

private static boolean inDaylighTime(final DateTime dt) {
return dt.getZone().toTimeZone().inDaylightTime(dt.toDate());
}

public void setDateTime(DateTime dt) {
this.dt = dt;
}
@@ -1045,7 +1038,7 @@ private RubyString mdump(final Ruby runtime) {
se >>>= 8;
}

RubyString string = RubyString.newString(runtime, new ByteList(dumpValue));
RubyString string = RubyString.newString(runtime, new ByteList(dumpValue, false));

// 1.9 includes more nsecs
copyInstanceVariablesInto(string);
@@ -1164,11 +1157,10 @@ public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObjec
// use Rational numerator and denominator to calculate nanos
RubyRational rational = (RubyRational) arg;

// These could have rounding errors if numerator or denominator are not integral and < long. Can they be?
long numerator = rational.getNumerator().getLongValue();
long denominator = rational.getDenominator().getLongValue();
BigInteger numerator = rational.getNumerator().getBigIntegerValue();
BigInteger denominator = rational.getDenominator().getBigIntegerValue();

BigDecimal nanosBD = BigDecimal.valueOf(numerator).divide(BigDecimal.valueOf(denominator), 50, BigDecimal.ROUND_HALF_UP).multiply(ONE_BILLION_BD);
BigDecimal nanosBD = new BigDecimal(numerator).divide(new BigDecimal(denominator), 50, BigDecimal.ROUND_HALF_UP).multiply(ONE_BILLION_BD);
BigInteger millis = nanosBD.divide(ONE_MILLION_BD).toBigInteger();
BigInteger nanos = nanosBD.remainder(ONE_MILLION_BD).toBigInteger();

Original file line number Diff line number Diff line change
@@ -372,7 +372,7 @@ protected static String printBacktraceMRI(RubyException exception, boolean conso

exception.printBacktrace(errorStream, 1);

return new String(baos.toByteArray());
return baos.toString();
}

private static final String FIRST_COLOR = "\033[0;31m";