Ruby Time differs from Java's time (Date)


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

=> -62167219201.0

time_millis = (time.to_f * 1000).round
=> -62167219201000

jdate = time.to_java
=> #Java::JavaUtil::Date:0x5a360f2b

=> “Sat Jan 03 00:59:59 CET 1”

=> -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.