lib/rubocop/cop/rails/time_zone.rb in rubocop-rails-2.2.0 vs lib/rubocop/cop/rails/time_zone.rb in rubocop-rails-2.2.1

- old
+ new

@@ -73,22 +73,35 @@ def autocorrect(node) lambda do |corrector| # add `.zone`: `Time.at` => `Time.zone.at` corrector.insert_after(node.children[0].source_range, '.zone') - # replace `Time.zone.current` => `Time.zone.now` - if node.method_name == :current + + case node.method_name + when :current + # replace `Time.zone.current` => `Time.zone.now` corrector.replace(node.loc.selector, 'now') + when :new + autocorrect_time_new(node, corrector) end + # prefer `Time` over `DateTime` class if strict? corrector.replace(node.children.first.source_range, 'Time') end remove_redundant_in_time_zone(corrector, node) end end private + + def autocorrect_time_new(node, corrector) + if node.arguments? + corrector.replace(node.loc.selector, 'local') + else + corrector.replace(node.loc.selector, 'now') + end + end # remove redundant `.in_time_zone` from `Time.zone.now.in_time_zone` def remove_redundant_in_time_zone(corrector, node) time_methods_called = extract_method_chain(node) return unless time_methods_called.include?(:in_time_zone) ||