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

RuboCop wrongly disallows building times with find_zone constructs in Rails code #4047

Closed
attilahorvath opened this issue Feb 17, 2017 · 1 comment

Comments

@attilahorvath
Copy link

In my codebase, I'm using the following constructs to build times in specified timezones:

Time.find_zone('EST').local(2017, 2, 17, 8, 0)

# and

Time.find_zone('EST').parse('10am')

However, RuboCop forbids me from using these, wrongly assuming that time zone information would be lost this way.

This is not the case, the resulting objects are of type ActiveSupport::TimeWithZone with the correct time zone set on them.


Expected behavior

RuboCop shouldn't warn against using constructs with find_zone.

Actual behavior

I am getting RuboCop warnings. As an example:

spec/models/my_model_spec.rb:39:24: C: Do not use Time.local without zone. Use one of Time.zone.local, Time.current, Time.local.in_time_zone, Time.local.utc, Time.local.getlocal, Time.local.iso8601, Time.local.jisx0301, Time.local.rfc3339, Time.local.to_i, Time.local.to_f instead.
        travel_to Time.find_zone('EST').local(2017, 2, 17, 8, 0) do

Steps to reproduce the problem

Write a code file containing similar constructs to the ones I've showed and run RuboCop with default settings against the file.

RuboCop version

$ bundle exec rubocop -V
0.47.1 (using Parser 2.4.0.0, running on ruby 2.3.1 x86_64-linux)
@attilahorvath
Copy link
Author

Submitted a pull request to fix this issue: #4054

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