Skip to content

Commit 2db2937

Browse files
committed
[refactor] we could do a faster-path Date.new
... since Date.civil always has a fixed chronology
1 parent 051ee46 commit 2db2937

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/java/arjdbc/util/DateTimeUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
* @author kares
5252
*/
5353
public abstract class DateTimeUtils {
54+
55+
private static final GJChronology CHRONO_ITALY_UTC = GJChronology.getInstance(DateTimeZone.UTC);
56+
5457
public static RubyTime toTime(final ThreadContext context, final IRubyObject value) {
5558
if (!(value instanceof RubyTime)) { // unlikely
5659
return (RubyTime) TypeConverter.convertToTypeWithCheck(value, context.runtime.getTime(), "to_time");
@@ -270,10 +273,7 @@ public static IRubyObject newDate(final ThreadContext context, final Date date)
270273
final int month = date.getMonth() + 1;
271274
final int day = date.getDate();
272275

273-
// TODO update to using fast-path without dynamic call (after >= 9.2)
274-
final Ruby runtime = context.runtime;
275-
final IRubyObject[] args = { runtime.newFixnum(year), runtime.newFixnum(month), runtime.newFixnum(day) };
276-
return runtime.getClass("Date").callMethod(context, "civil", args);
276+
return newDate(context, year, month, day, CHRONO_ITALY_UTC);
277277
}
278278

279279
// @Deprecated

0 commit comments

Comments
 (0)