|
37 | 37 | import org.jruby.RubyFixnum; |
38 | 38 | import org.jruby.RubyModule; |
39 | 39 | import org.jruby.RubyNumeric; |
| 40 | +import org.jruby.RubyTime; |
40 | 41 | import org.jruby.RubyObject; |
41 | 42 | import org.jruby.anno.JRubyMethod; |
42 | 43 | import org.jruby.exceptions.RaiseException; |
@@ -149,11 +150,20 @@ public IRubyObject set_trust(final IRubyObject arg) { |
149 | 150 | } |
150 | 151 |
|
151 | 152 | @JRubyMethod(name = "time=") |
152 | | - public IRubyObject set_time(final IRubyObject arg) { |
153 | | - setInstanceVariable("@time", arg); |
| 153 | + public IRubyObject set_time(final ThreadContext context, final IRubyObject arg) { |
| 154 | + // match CRuby: NUM2LONG(rb_Integer(time)) — accepts Time, Integer, or |
| 155 | + // anything convertible via #to_int, and stores epoch seconds internally |
| 156 | + setInstanceVariable("@time", toTime(context, arg)); |
154 | 157 | return arg; |
155 | 158 | } |
156 | 159 |
|
| 160 | + static RubyTime toTime(final ThreadContext context, final IRubyObject arg) { |
| 161 | + if (arg instanceof RubyTime) return (RubyTime) arg; |
| 162 | + // numeric (epoch seconds) — convert via Time.at |
| 163 | + long epoch = RubyNumeric.num2long(arg.callMethod(context, "to_int")); |
| 164 | + return RubyTime.newTime(context.runtime, epoch * 1000); |
| 165 | + } |
| 166 | + |
157 | 167 | @JRubyMethod |
158 | 168 | public IRubyObject add_path(final ThreadContext context, final IRubyObject arg) { |
159 | 169 | warn(context, "WARNING: unimplemented method called: OpenSSL::X509::Store#add_path"); |
|
0 commit comments