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

Timestamp ignores Time.use_zone #983

Closed
marcelrouw opened this issue Aug 19, 2016 · 2 comments
Closed

Timestamp ignores Time.use_zone #983

marcelrouw opened this issue Aug 19, 2016 · 2 comments
Labels

Comments

@marcelrouw
Copy link

We recently upgraded our rails application from rails 3.2 and ruby 1.9.3 (activerecord-oracle_enhanced-adapter 1.4.3) to rails 4.2.7 and ruby 2.3.1 (activerecord-oracle_enhanced-adapter 1.6.7). But I ran in to an issue with the Oracle timestamp field. It ignores the time zone set by Time.use_zone. But the date field still works as in the previous version.

CREATE TABLE TESTS
( ID NUMBER NOT NULL 
, TIMESTAMP_FIELD TIMESTAMP 
, DATE_FIELD DATE 
, CONSTRAINT TEST_PK PRIMARY KEY 
( ID )
 ENABLE 
);

application.rb

config.time_zone = 'Amsterdam'
config.active_record.default_timezone = :local

rails c (in our rails 4.2 application)

> Test.create(id: 1, timestamp_field: Time.now, date_field: Time.now)
#<Test id: "1", timestamp_field: "2016-08-18 17:06:51", date_field: "2016-08-18 15:06:51">

> puts Test.find_by_id(1).timestamp_field
2016-08-18 17:06:51 +0200

>  puts Test.find_by_id(1).date_field
2016-08-18 17:06:51 +0200

> x = Proc.new { puts Test.find_by_id(1).timestamp_field }
> Time.use_zone('Adelaide', &x)
2016-08-18 17:06:51 +0200

> x = Proc.new { puts Test.find_by_id(1).date_field }
> Time.use_zone('Adelaide', &x)
2016-08-19 00:36:51 +0930

In the rails 3.2 the timestamp_field did get affected by the Time.use_zone and showed the same time as date_field when using the Time.use_zone.

> Test.find_by_id(1).timestamp_field.class
Time
> Test.find_by_id(1).date_field.class
ActiveSupport::TimeWithZone

In rails 3.2 the timestamp_field is implemented by ActiveSupport::TimeWithZone as is data_field. So the different implementation is causing a problem for us. Is it possible to let a timestamp field act like an ActiveSupport::TimeWithZone?

@yahonda
Copy link
Collaborator

yahonda commented Aug 23, 2016

Hi,

Would you create an executable test case using this template?
https://github.com/yahonda/oracle-enhanced-your-testcase/blob/master/active_record_gem.rb

Since I was trying to reproduce it but unable to reproduce this result. timestamp_field and date_field have 2 hour difference at this point but my result is always same.

> Test.create(id: 1, timestamp_field: Time.now, date_field: Time.now)
#<Test id: "1", timestamp_field: "2016-08-18 17:06:51", date_field: "2016-08-18 15:06:51">

Thanks.

@stale stale bot added the wontfix label May 8, 2017
@stale
Copy link

stale bot commented May 8, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed May 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants