|
31 | 31 | import org.joda.time.Chronology;
|
32 | 32 | import org.joda.time.DateTime;
|
33 | 33 | import org.joda.time.DateTimeZone;
|
| 34 | +import org.joda.time.chrono.GJChronology; |
34 | 35 | import org.joda.time.chrono.ISOChronology;
|
35 | 36 | import org.jruby.Ruby;
|
36 | 37 | import org.jruby.RubyFloat;
|
@@ -263,6 +264,18 @@ public static IRubyObject newDate(final ThreadContext context, final Date date,
|
263 | 264 | return newDate(context, year, month, day, ISOChronology.getInstance(zone));
|
264 | 265 | }
|
265 | 266 |
|
| 267 | + @SuppressWarnings("deprecation") |
| 268 | + public static IRubyObject newDate(final ThreadContext context, final Date date) { |
| 269 | + final int year = date.getYear() + 1900; |
| 270 | + final int month = date.getMonth() + 1; |
| 271 | + final int day = date.getDate(); |
| 272 | + |
| 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); |
| 277 | + } |
| 278 | + |
266 | 279 | // @Deprecated
|
267 | 280 | public static Timestamp convertToTimestamp(final RubyFloat value) {
|
268 | 281 | final Timestamp timestamp = new Timestamp(value.getLongValue() * 1000); // millis
|
@@ -557,7 +570,7 @@ else if ( e1 == 'B' && str.charAt(start + 1) == 'C' ) {
|
557 | 570 | }
|
558 | 571 |
|
559 | 572 | private static IRubyObject newDate(final ThreadContext context, final int year, final int month, final int day,
|
560 |
| - final ISOChronology chronology) { |
| 573 | + final Chronology chronology) { |
561 | 574 | // NOTE: JRuby really needs a native date.rb until than its a bit costly going from ...
|
562 | 575 | // java.sql.Date -> allocating a DateTime proxy, help a bit by shooting at the internals
|
563 | 576 | //
|
|
0 commit comments