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

Wrong Time.zone suggestion #1773

Closed
net1957 opened this issue Apr 8, 2015 · 2 comments
Closed

Wrong Time.zone suggestion #1773

net1957 opened this issue Apr 8, 2015 · 2 comments

Comments

@net1957
Copy link

net1957 commented Apr 8, 2015

For this code

  def validate_datetime(datetime = nil, format = '%d/%m/%Y %H:%M:%S')
    return nil if datetime.nil? || datetime.empty?
    Time.strptime(datetime, format).in_time_zone
  rescue StandardError
    nil
  end

I get this message

app/controllers/application_controller.rb:48:10: C: Do not use Time.[:strptime] without zone. Use #Time.zone.[:strptime] instead.
    Time.strptime(datetime, format).in_time_zone

but Time.zone.strptime doesn't exist....

rubocop 0.30.0
rails 4.2.1

Regards

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 9, 2015

//cc @palkan

palkan added a commit to palkan/rubocop that referenced this issue Apr 9, 2015
@palkan
Copy link
Contributor

palkan commented Apr 9, 2015

There was a kind of typo: we should detect incorrect usage of strftime, but not strptime ('cause there is no ActiveSupport::TimeZone alternative).

PR attached.

palkan added a commit to palkan/rubocop that referenced this issue Apr 9, 2015
@bbatsov bbatsov closed this as completed in f4b04eb Apr 9, 2015
bbatsov added a commit that referenced this issue Apr 9, 2015
[Fix #1773] Fix typo ('strptime' to 'strftime')
crimsonknave pushed a commit to crimsonknave/rubocop that referenced this issue Apr 13, 2015
koic added a commit to koic/rubocop that referenced this issue Jan 5, 2018
Follow up of rubocop#5381 (comment).

It seems that there is a mistake in solving the Issue below.

rubocop#1773

From Rails 4.2 to Rails 5.2 (beta), The following code will result in an error.

```console
> str = '2015-03-02 19:05:37'
> Time.zone.strftime(str, "%Y-%m-%d %H:%M%Z")
NoMethodError: undefined method `strftime' for #<ActiveSupport::TimeZone:0x00007fdaed438c88>
```

AFIAK, `ActiveSupport::TimeZone#strftime` does not exist in Rails 4.2 at least.

Previously, rubocop#1773 was thought to mistype `Time.zone.strftime` to
`Time.zone.strptime`. However, I think that it was false positives
because `ActiveSupport::TimeZone#strptime` introduced in Rails 5.0
does not exist in Rails 4.2.

rails/rails@a5e507f

In this PR, `ActiveSupport::TimeZone#strftime` which does not exist is
removed from detection targets.

I'm judging that this change has no effect on codes that works as expected.
bbatsov pushed a commit that referenced this issue Jan 5, 2018
Follow up of #5381 (comment).

It seems that there is a mistake in solving the Issue below.

#1773

From Rails 4.2 to Rails 5.2 (beta), The following code will result in an error.

```console
> str = '2015-03-02 19:05:37'
> Time.zone.strftime(str, "%Y-%m-%d %H:%M%Z")
NoMethodError: undefined method `strftime' for #<ActiveSupport::TimeZone:0x00007fdaed438c88>
```

AFIAK, `ActiveSupport::TimeZone#strftime` does not exist in Rails 4.2 at least.

Previously, #1773 was thought to mistype `Time.zone.strftime` to
`Time.zone.strptime`. However, I think that it was false positives
because `ActiveSupport::TimeZone#strptime` introduced in Rails 5.0
does not exist in Rails 4.2.

rails/rails@a5e507f

In this PR, `ActiveSupport::TimeZone#strftime` which does not exist is
removed from detection targets.

I'm judging that this change has no effect on codes that works as expected.
koic added a commit to rubocop/rubocop-rails that referenced this issue Oct 26, 2018
Follow up of rubocop/rubocop#5381 (comment).

It seems that there is a mistake in solving the Issue below.

rubocop/rubocop#1773

From Rails 4.2 to Rails 5.2 (beta), The following code will result in an error.

```console
> str = '2015-03-02 19:05:37'
> Time.zone.strftime(str, "%Y-%m-%d %H:%M%Z")
NoMethodError: undefined method `strftime' for #<ActiveSupport::TimeZone:0x00007fdaed438c88>
```

AFIAK, `ActiveSupport::TimeZone#strftime` does not exist in Rails 4.2 at least.

Previously, #1773 was thought to mistype `Time.zone.strftime` to
`Time.zone.strptime`. However, I think that it was false positives
because `ActiveSupport::TimeZone#strptime` introduced in Rails 5.0
does not exist in Rails 4.2.

rails/rails@a5e507f

In this PR, `ActiveSupport::TimeZone#strftime` which does not exist is
removed from detection targets.

I'm judging that this change has no effect on codes that works as expected.
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

3 participants