activerecord-jdbc-adapter
activerecord-jdbc-adapter copied to clipboard
Positive time zones and Daylight Savings (Australia)
When saving a date that matches the beginning of day light savings, the previous day is persisted.
source code: https://github.com/jruby/activerecord-jdbc-adapter/blob/master/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java#L390
jruby-9.2.19.0 :032 > java_date = Date.parse('2021-10-03').to_java(org.jruby.ext.date.RubyDate)
=> #<Date: 2021-10-03 ((2459491j,0s,0n),+0s,2299161j)>
jruby-9.2.19.0 :033 > millis = java_date.getDateTime.getMillis
=> 1633219200000
jruby-9.2.19.0 :034 > offset = java.util.TimeZone.getDefault.getOffset(millis)
=> 39600000
jruby-9.2.19.0 :035 > java.sql.Date.new(millis - offset).to_s
=> "Sat Oct 02 23:00:00 AEST 2021"
Added the following test scenario in date_test and it fails
JRUBY_OPTS=-J-Duser.timezone=Australia/Melbourne rake test_postgres
def test_prepared_statement_for_date_column_sends_correct_date_to_postgres
Post.create!
date = Date.new(2020, 10, 04)
Post.first.update_columns published_on: date
assert_equal date, Post.first.published_on
ensure
Post.connection.execute 'TRUNCATE posts;'
end
Failure:
test_prepared_statement_for_date_column_sends_correct_date_to_postgres(DateTest::ContextDaylightSavings)
~/activerecord-jdbc-adapter/test/db/postgresql/date_test.rb:34:in `test_prepared_statement_for_date_column_sends_correct_date_to_postgres'
31: date = Date.new(2020, 10, 04)
32: Post.first.update_columns published_on: date
33:
=> 34: assert_equal date, Post.first.published_on
35: ensure
36: Post.connection.execute 'TRUNCATE posts;'
37: end
<Sun, 04 Oct 2020> expected but was
<Sat, 03 Oct 2020>
diff:
? Sun, 04 Oct 2020
? at 3