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: 796e3e1d821d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 384e1ea1e951
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 1, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    headius Charles Oliver Nutter
    Copy the full SHA
    ecb78ee View commit details
  2. Copy the full SHA
    384e1ea View commit details
Showing with 24 additions and 14 deletions.
  1. +9 −1 core/src/main/java/org/jruby/runtime/encoding/EncodingService.java
  2. +15 −13 core/src/main/java/org/jruby/util/TimeZoneConverter.java
Original file line number Diff line number Diff line change
@@ -135,6 +135,8 @@ public Entry findEncodingOrAliasEntry(byte[] bytes) {
return e != null ? e : findAliasEntry(bytes);
}

private static ByteList defaultCharsetName;

// rb_locale_charmap...mostly
public Encoding getLocaleEncoding() {
final Encoding consoleEncoding = getConsoleEncoding();
@@ -143,7 +145,13 @@ public Encoding getLocaleEncoding() {
return consoleEncoding;
}

Entry entry = findEncodingOrAliasEntry(new ByteList(Charset.defaultCharset().name().getBytes()));
ByteList encName = defaultCharsetName;
if (encName == null) {
encName = new ByteList(Charset.defaultCharset().name().getBytes(), false);
defaultCharsetName = encName;
}

final Entry entry = findEncodingOrAliasEntry(encName);
return entry == null ? ASCIIEncoding.INSTANCE : entry.getEncoding();
}

28 changes: 15 additions & 13 deletions core/src/main/java/org/jruby/util/TimeZoneConverter.java
Original file line number Diff line number Diff line change
@@ -25,11 +25,13 @@
***** END LICENSE BLOCK *****/
package org.jruby.util;

import java.util.List;

/**
* This is utility class to convert given timezone into integer based timezone
* diff. It's ported from ext/date/date_parse.c in MRI 2.3.1 under BSDL.
* @see https://github.com/ruby/ruby/blob/394fa89c67722d35bdda89f10c7de5c304a5efb1/ext/date/date_parse.c
*/
// @see https://github.com/ruby/ruby/blob/394fa89c67722d35bdda89f10c7de5c304a5efb1/ext/date/date_parse.c
public class TimeZoneConverter {
// Ports zones_source in ext/date/date_parse.c in MRI 2.3.1 under BSDL.
private static int getOffsetFromZonesSource(String z) {
@@ -423,22 +425,22 @@ public static int dateZoneToDiff(String zone) {
z = z.substring(1);

int hour = 0, min = 0, sec = 0;
if (z.contains(":")) {
final String[] splited = z.split(":");
if (splited.length == 2) {
hour = Integer.parseInt(splited[0]);
min = Integer.parseInt(splited[1]);
if (z.indexOf(':') != -1) {
final List<String> splited = StringSupport.split(z, ':');
if (splited.size() == 2) {
hour = Integer.parseInt(splited.get(0));
min = Integer.parseInt(splited.get(1));
} else {
hour = Integer.parseInt(splited[0]);
min = Integer.parseInt(splited[1]);
sec = Integer.parseInt(splited[2]);
hour = Integer.parseInt(splited.get(0));
min = Integer.parseInt(splited.get(1));
sec = Integer.parseInt(splited.get(2));
}

} else if (z.contains(",") || z.contains(".")) {
} else if (z.indexOf(',') != -1 || z.indexOf('.') != -1) {
// TODO min = Rational(fr.to_i, 10**fr.size) * 60
String[] splited = z.split("[\\.,]");
hour = Integer.parseInt(splited[0]);
min = (int)(Integer.parseInt(splited[1]) * 60 / Math.pow(10, splited[1].length()));
min = (int) (Integer.parseInt(splited[1]) * 60 / Math.pow(10, splited[1].length()));

} else {
final int len = z.length();
@@ -469,6 +471,6 @@ public static int dateZoneToDiff(String zone) {
return sign ? offset : -offset;
}

private TimeZoneConverter() {
}
private TimeZoneConverter() { /* no instances */ }

}