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: 792530e7d450
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0cfdfe50a1f8
Choose a head ref
  • 5 commits
  • 3 files changed
  • 2 contributors

Commits on Nov 15, 2014

  1. Copy the full SHA
    9722c95 View commit details
  2. Copy the full SHA
    baddc69 View commit details
  3. Copy the full SHA
    bedb075 View commit details
  4. Remove 9 test exclusions

    cheald committed Nov 15, 2014
    Copy the full SHA
    97ff9bb View commit details

Commits on Nov 18, 2014

  1. Merge pull request #2202 from cheald/time_fixes

    Multiple fixes for the MRI Time suite
    enebo committed Nov 18, 2014
    Copy the full SHA
    0cfdfe5 View commit details
Showing with 24 additions and 30 deletions.
  1. +16 −8 core/src/main/java/org/jruby/RubyTime.java
  2. +5 −10 core/src/main/java/org/jruby/util/RubyDateFormatter.java
  3. +3 −12 test/mri/excludes/TestTime.rb
24 changes: 16 additions & 8 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jcodings.specific.USASCIIEncoding;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
@@ -92,10 +93,10 @@ public class RubyTime extends RubyObject {
// the legacy TZ format in order to convert it to the newer format
// understood by Java API.
private static final Pattern TZ_PATTERN
= Pattern.compile("([^-\\+\\d]+)?([\\+-]?)(\\d+)(?::(\\d+))?(?::\\d+)?");
= Pattern.compile("([^-\\+\\d]+)?([\\+-]?)(\\d+)(?::(\\d+))?(?::(\\d+))?");

private static final Pattern TIME_OFFSET_PATTERN
= Pattern.compile("([\\+-])(\\d\\d):(\\d\\d)");
= Pattern.compile("([\\+-])(\\d\\d):(\\d\\d)(?::(\\d\\d))?");

private static final ByteList TZ_STRING = ByteList.create("TZ");

@@ -169,13 +170,14 @@ private static DateTimeZone parseTZString(Ruby runtime, String zone) {
String sign = tzMatcher.group(2);
String hours = tzMatcher.group(3);
String minutes = tzMatcher.group(4);
String seconds= tzMatcher.group(5);

if (zoneName == null) {
zoneName = "";
}

// Sign is reversed in legacy TZ notation
return getTimeZoneFromHHMM(runtime, zoneName, sign.equals("-"), hours, minutes);
return getTimeZoneFromHHMM(runtime, zoneName, sign.equals("-"), hours, minutes, seconds);
} else {
if (LONG_TZNAME.containsKey(upZone)) {
zone = LONG_TZNAME.get(upZone);
@@ -228,7 +230,8 @@ public static DateTimeZone getTimeZoneFromUtcOffset(Ruby runtime, IRubyObject ut
String sign = offsetMatcher.group(1);
String hours = offsetMatcher.group(2);
String minutes = offsetMatcher.group(3);
dtz = getTimeZoneFromHHMM(runtime, "", !sign.equals("-"), hours, minutes);
String seconds = offsetMatcher.group(4);
dtz = getTimeZoneFromHHMM(runtime, "", !sign.equals("-"), hours, minutes, seconds);
} else {
IRubyObject numericOffset = numExact(runtime, utcOffset);
int newOffset = (int)Math.round(numericOffset.convertToFloat().getDoubleValue() * 1000);
@@ -292,18 +295,23 @@ private static void exactTypeError(Ruby runtime, IRubyObject received) {
String.format("Can't convert %s into an exact number", received.getMetaClass().getRealClass()));
}

private static DateTimeZone getTimeZoneFromHHMM(Ruby runtime, String name, boolean positive, String hours, String minutes) {
private static DateTimeZone getTimeZoneFromHHMM(Ruby runtime, String name, boolean positive, String hours, String minutes, String seconds) {
int h = Integer.parseInt(hours);
int m = 0;
int s = 0;
if (minutes != null) {
m = Integer.parseInt(minutes);
}

if (seconds != null) {
s = Integer.parseInt(seconds);
}

if (h > 23 || m > 59) {
throw runtime.newArgumentError("utc_offset out of range");
}

int offset = (positive ? +1 : -1) * ((h * 60) + m) * 60 * 1000;
int offset = (positive ? +1 : -1) * ((h * 3600) + m * 60 + s) * 1000;
return timeZoneWithOffset(name, offset);
}

@@ -683,7 +691,7 @@ public RubyString asctime() {
simpleDateFormat = TWO_DAY_CTIME_FORMATTER;
}
String result = simpleDateFormat.print(dt);
return getRuntime().newString(result);
return RubyString.newString(getRuntime(), result, USASCIIEncoding.INSTANCE);
}

@Override
@@ -716,7 +724,7 @@ private IRubyObject inspectCommon(DateTimeFormatter formatter, DateTimeFormatter
result = simpleDateFormat.print(invertedDT);
}

return getRuntime().newString(result);
return RubyString.newString(getRuntime(), result, USASCIIEncoding.INSTANCE);
}

@JRubyMethod
15 changes: 5 additions & 10 deletions core/src/main/java/org/jruby/util/RubyDateFormatter.java
Original file line number Diff line number Diff line change
@@ -619,16 +619,11 @@ private String formatZone(int colons, int value, RubyTimeOutputFormatter formatt
after = ":" + mm + ":" + ss;
break;
case 3: // %:::z -> +hh[:mm[:ss]]
if (minutes == 0) {
if (seconds == 0) { // +hh
defaultWidth = 3;
after = "";
} else { // +hh:mm
return formatZone(1, value, formatter);
}
} else { // +hh:mm:ss
return formatZone(2, value, formatter);
}
StringBuilder sb = new StringBuilder();
if (minutes != 0 || seconds != 0) sb.append(":").append(mm);
if (seconds != 0) sb.append(":").append(ss);
after = sb.toString();
defaultWidth = after.length() + 3;
break;
}

15 changes: 3 additions & 12 deletions test/mri/excludes/TestTime.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
exclude :test_asctime, "needs investigation"
exclude :test_at, "needs investigation"
exclude :test_at_rational, "needs investigation"
exclude :test_at, "MRI uses less precision than JRuby, which causes it to produce incorrect values"
exclude :test_at_rational, "MRI uses less precision than JRuby, which causes it to produce incorrect values"
exclude :test_future, "needs investigation"
exclude :test_marshal_nsec_191, "needs investigation"
exclude :test_marshal_zone_gc, "should not be an issue on JRuby and slow"
exclude :test_new, "needs investigation"
exclude :test_past, "needs investigation"
exclude :test_plus_type, "needs investigation"
exclude :test_reinitialize, "needs investigation"
exclude :test_strftime, "needs investigation"
exclude :test_strfimte_zoneoffset, "needs investigation"
exclude :test_strftime_invalid_flags, "needs investigation"
exclude :test_strftime_padding, "needs investigation"
exclude :test_strftime_rational, "needs investigation"
exclude :test_strftime_too_wide, "needs investigation"
exclude :test_time_add, "needs investigation"
exclude :test_time_interval, "needs investigation"
exclude :test_to_r, "needs investigation"
exclude :test_to_s, "needs investigation"
exclude :test_utc_or_local, "needs investigation"
exclude :test_utc_or_local, "needs investigation"