lib/rubocop/cop/rails/time_zone.rb in rubocop-rails-2.10.1 vs lib/rubocop/cop/rails/time_zone.rb in rubocop-rails-2.11.0
- old
+ new
@@ -6,45 +6,37 @@
# This cop checks for the use of Time methods without zone.
#
# Built on top of Ruby on Rails style guide (https://rails.rubystyle.guide#time)
# and the article http://danilenko.org/2012/7/6/rails_timezones/
#
- # Two styles are supported for this cop. When EnforcedStyle is 'strict'
- # then only use of Time.zone is allowed.
+ # Two styles are supported for this cop. When `EnforcedStyle` is 'strict'
+ # then only use of `Time.zone` is allowed.
#
# When EnforcedStyle is 'flexible' then it's also allowed
- # to use Time.in_time_zone.
+ # to use `Time#in_time_zone`.
#
- # @example EnforcedStyle: strict
- # # `strict` means that `Time` should be used with `zone`.
- #
+ # @example
# # bad
# Time.now
# Time.parse('2015-03-02T19:05:37')
#
- # # bad
- # Time.current
- # Time.at(timestamp).in_time_zone
- #
# # good
+ # Time.current
# Time.zone.now
# Time.zone.parse('2015-03-02T19:05:37')
# Time.zone.parse('2015-03-02T19:05:37Z') # Respect ISO 8601 format with timezone specifier.
#
- # @example EnforcedStyle: flexible (default)
- # # `flexible` allows usage of `in_time_zone` instead of `zone`.
+ # @example EnforcedStyle: strict
+ # # `strict` means that `Time` should be used with `zone`.
#
# # bad
- # Time.now
- # Time.parse('2015-03-02T19:05:37')
+ # Time.at(timestamp).in_time_zone
#
- # # good
- # Time.zone.now
- # Time.zone.parse('2015-03-02T19:05:37')
+ # @example EnforcedStyle: flexible (default)
+ # # `flexible` allows usage of `in_time_zone` instead of `zone`.
#
# # good
- # Time.current
# Time.at(timestamp).in_time_zone
class TimeZone < Base
include ConfigurableEnforcedStyle
extend AutoCorrector
@@ -57,10 +49,10 @@
MSG_LOCALTIME = 'Do not use `Time.localtime` without ' \
'offset or zone.'
GOOD_METHODS = %i[zone zone_default find_zone find_zone!].freeze
- DANGEROUS_METHODS = %i[now local new parse at current].freeze
+ DANGEROUS_METHODS = %i[now local new parse at].freeze
ACCEPTED_METHODS = %i[in_time_zone utc getlocal xmlschema iso8601
jisx0301 rfc3339 httpdate to_i to_f].freeze
TIMEZONE_SPECIFIER = /[A-z]/.freeze