Created
October 30, 2017 14:06
-
-
Save headius/6ee8683674d1c38a330b1a6c7bc7d5f6 to your computer and use it in GitHub Desktop.
Construct all DateTime in RubyTime with GJ chrono (jruby/jruby#4822)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/main/java/org/jruby/RubyTime.java b/core/src/main/java/org/jruby/RubyTime.java | |
index 395e948aca..e1cded5648 100644 | |
--- a/core/src/main/java/org/jruby/RubyTime.java | |
+++ b/core/src/main/java/org/jruby/RubyTime.java | |
@@ -43,6 +43,7 @@ import org.jcodings.specific.USASCIIEncoding; | |
import org.joda.time.DateTime; | |
import org.joda.time.DateTimeZone; | |
import org.joda.time.IllegalFieldValueException; | |
+import org.joda.time.chrono.GJChronology; | |
import org.joda.time.format.DateTimeFormat; | |
import org.joda.time.format.DateTimeFormatter; | |
import org.joda.time.tz.FixedDateTimeZone; | |
@@ -414,7 +415,7 @@ public class RubyTime extends RubyObject { | |
msecs = System.currentTimeMillis(); | |
nsecs = 0; | |
} | |
- DateTime dt = new DateTime(msecs, dtz); | |
+ DateTime dt = new DateTime(msecs, GJChronology.getInstance(dtz)); | |
RubyTime rt = new RubyTime(runtime, klass, dt); | |
rt.setNSec(nsecs); | |
@@ -462,13 +463,13 @@ public class RubyTime extends RubyObject { | |
} | |
public static RubyTime newTime(Ruby runtime, long milliseconds) { | |
- return newTime(runtime, new DateTime(milliseconds)); | |
+ return newTime(runtime, new DateTime(milliseconds, GJChronology.getInstance())); | |
} | |
public static RubyTime newTimeFromNanoseconds(Ruby runtime, long nanoseconds) { | |
long milliseconds = nanoseconds / 1000000; | |
long extraNanoseconds = nanoseconds % 1000000; | |
- return RubyTime.newTime(runtime, new DateTime(milliseconds), extraNanoseconds); | |
+ return RubyTime.newTime(runtime, new DateTime(milliseconds, GJChronology.getInstance()), extraNanoseconds); | |
} | |
public static RubyTime newTime(Ruby runtime, DateTime dt) { | |
@@ -665,7 +666,7 @@ public class RubyTime extends RubyObject { | |
} | |
RubyTime newTime = new RubyTime(getRuntime(), getMetaClass()); | |
- newTime.dt = new DateTime(newMillisPart).withZone(dt.getZone()); | |
+ newTime.dt = new DateTime(newMillisPart).withZone(dt.getZone()).withChronology(GJChronology.getInstance()); | |
newTime.setNSec(newNanosPart); | |
return newTime; | |
@@ -720,7 +721,7 @@ public class RubyTime extends RubyObject { | |
} | |
RubyTime newTime = new RubyTime(getRuntime(), getMetaClass()); | |
- newTime.dt = new DateTime(time).withZone(dt.getZone()); | |
+ newTime.dt = new DateTime(time).withZone(dt.getZone()).withChronology(GJChronology.getInstance()); | |
newTime.setNSec(nano); | |
return newTime; | |
@@ -1078,7 +1079,7 @@ public class RubyTime extends RubyObject { | |
public static IRubyObject s_new(IRubyObject recv, IRubyObject[] args, Block block) { | |
Ruby runtime = recv.getRuntime(); | |
- RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(getLocalTimeZone(runtime))); | |
+ RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(GJChronology.getInstance(getLocalTimeZone(runtime)))); | |
time.callInit(args, block); | |
return time; | |
} | |
@@ -1155,7 +1156,7 @@ public class RubyTime extends RubyObject { | |
try { | |
time = new RubyTime(runtime, (RubyClass) recv, | |
- new DateTime(millisecs, getLocalTimeZone(runtime))); | |
+ new DateTime(millisecs, GJChronology.getInstance(getLocalTimeZone(runtime)))); | |
} | |
// joda-time 2.5 can throw this exception - seen locally | |
catch(ArithmeticException e1) { | |
@@ -1178,7 +1179,7 @@ public class RubyTime extends RubyObject { | |
public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObject arg1, IRubyObject arg2) { | |
Ruby runtime = context.runtime; | |
- RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(0L, getLocalTimeZone(runtime))); | |
+ RubyTime time = new RubyTime(runtime, (RubyClass) recv, new DateTime(0L, GJChronology.getInstance(getLocalTimeZone(runtime)))); | |
long millisecs; | |
long nanosecs = 0; | |
@@ -1326,7 +1327,7 @@ public class RubyTime extends RubyObject { | |
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { | |
Ruby runtime = recv.getRuntime(); | |
- DateTime dt = new DateTime(DateTimeZone.UTC); | |
+ DateTime dt = new DateTime(GJChronology.getInstance(DateTimeZone.UTC)); | |
byte[] fromAsBytes; | |
fromAsBytes = from.convertToString().getBytes(); | |
@@ -1515,7 +1516,7 @@ public class RubyTime extends RubyObject { | |
DateTime dt; | |
// set up with min values and then add to allow rolling over | |
try { | |
- dt = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); | |
+ dt = new DateTime(year, 1, 1, 0, 0, 0, 0, GJChronology.getInstance(DateTimeZone.UTC)); | |
dt = dt.plusMonths(month - 1) | |
.plusDays(int_args[0] - 1) | |
diff --git a/lib/ruby/stdlib/date.rb b/lib/ruby/stdlib/date.rb | |
index ad36703759..bffae8bcbd 100644 | |
--- a/lib/ruby/stdlib/date.rb | |
+++ b/lib/ruby/stdlib/date.rb | |
@@ -1887,7 +1887,7 @@ class Time | |
s = [sec, 59].min | |
ms, sub_millis = nsec.divmod(1_000_000) # expects ns precision for Time | |
sub_millis = Rational(sub_millis, 1_000_000) if sub_millis != 0 | |
- dt = Date::JODA::DateTime.new(1000 * to_i + ms, Date.send(:chronology, sg, of)) | |
+ dt = Date::JODA::DateTime.new(1000 * to_i + ms, Date.send(:chronology, sg, of).tap{|x|puts x}) | |
klass.new!(dt, of, sg, sub_millis) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment