Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positive time zones and Daylight Savings (Australia) #1093

Open
sebastianguarin opened this issue Sep 22, 2021 · 0 comments
Open

Positive time zones and Daylight Savings (Australia) #1093

sebastianguarin opened this issue Sep 22, 2021 · 0 comments

Comments

@sebastianguarin
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant