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 complains about DateTime#to_time #288

Closed
MatheusRich opened this issue Jul 7, 2020 · 2 comments · Fixed by #481
Closed

Rubocop complains about DateTime#to_time #288

MatheusRich opened this issue Jul 7, 2020 · 2 comments · Fixed by #481

Comments

@MatheusRich
Copy link

MatheusRich commented Jul 7, 2020

Expected behavior

Rubocop should not complain about to_time on DateTime objects, since they do know about the timezone.

Actual behavior

Rubocops raises the error Do not use 'to_time' on Date objects, because they know nothing about the time zone in use. (convention:Rails/Date)

Steps to reproduce the problem

date = DateTime.current
time = date.to_time

puts time

RuboCop version

bundle exec rubocop -V
0.82.0 (using Parser 2.7.1.4, running on ruby 2.7.1 x86_64-linux)
@andyw8
Copy link
Contributor

andyw8 commented Jul 8, 2020

If this is indeed the case, then the style guide should also be updated:

https://github.com/rubocop-hq/rails-style-guide#to-time

@derikson
Copy link

derikson commented Mar 3, 2021

The style guide refers to String#to_time only. Even Date#to_time knows about timezones.

@koic koic mentioned this issue Apr 27, 2021
20 tasks
koic added a commit to koic/rubocop-rails that referenced this issue May 10, 2021
Fixes rubocop#288.

This PR adds `AllowToTime` option (`true` by default) to `Rails/Date`.
@koic koic closed this as completed in #481 May 12, 2021
koic added a commit that referenced this issue May 12, 2021
[Fix #288] Add `AllowToTime` option to `Rails/Date`
koic added a commit to koic/rubocop-rails that referenced this issue May 17, 2021
Fixes rubocop#288.

This PR adds `AllowToTime` option (`true` by default) to `Rails/Date`.
koic added a commit to koic/rubocop-rails that referenced this issue May 17, 2021
Fixes rubocop#288.

This PR adds `AllowToTime` option (`true` by default) to `Rails/Date`.
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

Successfully merging a pull request may close this issue.

3 participants