Forum: JRuby Ruby Time differs from Java's time (Date)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Caa2df9372ffa0a9e95b2bab1e8fea34?d=identicon&s=25 Karol Bucek (Guest)
on 2013-12-11 09:44
(Received via mailing list)

There was a bug with Time around BC in JRuby 1.7.x that has been fixed
in a
recent release - but I still can not get AR-JDBC compatibility around
(with prepared-statements) due different time interpretation in Ruby and
Java for the same milliseconds.

So having a (ruby) Time that's BC ends up "messing up" the date as it
to be a (java) Date.

Joda's underlying (RubyTime internals) DateTime seems to be correct (I
getting the millis from it) but feeding a java.sql.Timestamp the same
millis value does get interpreted as a different date :

>> time = -1, 12, 31, 23, 59, 59, 0
=> -0001-12-31 23:59:59 UTC
>> time.to_f
=> -62167219201.0
>> time_millis = (time.to_f * 1000).round
=> -62167219201000
>> jdate = time.to_java
=> #<Java::JavaUtil::Date:0x5a360f2b>
>> jdate.toString
=> "Sat Jan 03 00:59:59 CET 1"
>> jdate.getTime
=> -62167219201000
>>"yyyy-MM-dd HH:mm:ss").format jdate
=> "0001-01-03 00:59:59"

Just ignore the fact that the Time and Date are in different time-zones
that's taken care of but still the date seems to be quite messed up ...
it's still :

<-0001-12-31 23:59:59> (set) vs. <-0001-01-02 23:59:59> (get - when
the set value)

Anyone knows if this is a JDK Calendar issue or am I missing something
(I've tried making the TZ used is UTC from the Java part but got the
same) ?

Thanks for pointers & ideas, K.
This topic is locked and can not be replied to.