Skip to content

Incorrect auto-correction: Time.new -> Time.zone.new #86

Closed
@doloopwhile

Description

Rails/TimeZone will substitute Time.new to Time.zone.new with --auto-correct option.

However, Time.zone.new is not a constructor of TimeWithZone.
It should be Time.zone.local.


Expected behavior

Substitutes Time.new with Time.zone.local.

Actual behavior

Substitutes Time.new with Time.zone.new.

Steps to reproduce the problem

$ gem install rubocop -v 0.72.0
$ gem install rubocop-rails -v 2.2.0
$ echo 'require: rubocop-rails' > .rubocop.yml
$ echo 'Time.new(2016, 7, 8, 12, 34, 56)' > a.rb
$ rubocop --only Rails/TimeZone --auto-correct a.rb
Inspecting 1 file
C

Offenses:

a.rb:1:6: C: [Corrected] Rails/TimeZone: Do not use Time.new without zone. Use one of Time.zone.local, Time.current, Time.new.in_time_zone, Time.new.utc, Time.new.getlocal, Time.new.xmlschema, Time.new.iso8601, Time.new.jisx0301, Time.new.rfc3339, Time.new.httpdate, Time.new.to_i, Time.new.to_f instead. (https://github.com/rubocop-hq/rails-style-guide#time, http://danilenko.org/2012/7/6/rails_timezones)
Time.new(2016, 7, 8, 12, 34, 56)
     ^^^

1 file inspected, 1 offense detected, 1 offense corrected
$ cat a.rb
Time.zone.new(2016, 7, 8, 12, 34, 56)

RuboCop version

$ rubocop -V
0.72.0 (using Parser 2.6.3.0, running on ruby 2.6.2 x86_64-darwin17)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions