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

Make #to_fs the default replacement for #to_s(:format) #44354

Merged
merged 5 commits into from
Feb 8, 2022

Conversation

dhh
Copy link
Member

@dhh dhh commented Feb 7, 2022

The first take of #to_formatted_s was just too cumbersome for a method used that frequently. It also mixed abbreviation and not in a bit of an unholy mix.

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but the tests are not testing the existence of the alias anymore. Someone could come and delete it, which would be a breaking change and we would not know. I commented in a few places that the alias was being tested, but there are more in the body of changes of this PR which I didn't comment.

#
# === Examples
# datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
#
# datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
# datetime.to_fs(:db) # => "2007-12-04 00:00:00"
# datetime.to_fs(:db) # => "2007-12-04 00:00:00"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# datetime.to_fs(:db) # => "2007-12-04 00:00:00"
# datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"

assert_equal "2005-02-21", date.to_fs(:db)
assert_equal "2005-02-21", date.to_fs(:inspect)
assert_equal "21 Feb 2005", date.to_fs(:rfc822)
assert_equal "2005-02-21", date.to_fs(:iso8601)
assert_equal "21 Feb", date.to_fs(:short)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_equal "21 Feb", date.to_fs(:short)
assert_equal "21 Feb", date.to_formatted_s(:short)

needs to keep testing the alias

assert_equal "2009-02-05T14:30:05+00:00", DateTime.civil(2009, 2, 5, 14, 30, 5).to_formatted_s(:iso8601)
assert_equal "2009-02-05T14:30:05-06:00", DateTime.civil(2009, 2, 5, 14, 30, 5, Rational(-21600, 86400)).to_fs(:iso8601)
assert_equal "2008-06-09T04:05:01-05:00", DateTime.civil(2008, 6, 9, 4, 5, 1, Rational(-18000, 86400)).to_fs(:iso8601)
assert_equal "2009-02-05T14:30:05+00:00", DateTime.civil(2009, 2, 5, 14, 30, 5).to_fs(:iso8601)
end

assert_equal "2005-02-21 14:30:00", datetime.to_fs(:db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_equal "2005-02-21 14:30:00", datetime.to_fs(:db)
assert_equal "2005-02-21 14:30:00", datetime.to_formatted_s(:db)

@rafaelfranca
Copy link
Member

I'm taking over this PR to fix the test/doc problem.

@rafaelfranca rafaelfranca merged commit de7c495 into main Feb 8, 2022
@rafaelfranca rafaelfranca deleted the to-fs-as-the-primary branch February 8, 2022 16:50
rafaelfranca added a commit that referenced this pull request Feb 8, 2022
Make #to_fs the default replacement for #to_s(:format)
r7kamura added a commit to r7kamura/rubocop-rails_deprecation that referenced this pull request Mar 14, 2022
sambostock added a commit to Shopify/money that referenced this pull request Mar 17, 2022
rails/rails#44354 introduces `to_fs`, and makes `to_formatted_s` an alias for
it, so if we added `to_formatted_s` to match APIs, then we should add `to_fs`
as well.
sambostock added a commit to Shopify/money that referenced this pull request Mar 17, 2022
Since rails/rails#44354 implements `to_formatted_s` as an alias for `to_fs`, it
makes sense for us to do it the same way.
gbp added a commit to mysociety/alaveteli that referenced this pull request Apr 11, 2022
Use replacement `#to_fs` instead. Fixes deprecation warnings:
`TimeWithZone#to_s(:db) is deprecated. Please use TimeWithZone#to_fs(:db) instead.`

See rails/rails#44354
tnir added a commit to tnir/forem that referenced this pull request Apr 11, 2022
jeremyf pushed a commit to forem/forem that referenced this pull request Apr 11, 2022
koic added a commit to koic/rails-style-guide that referenced this pull request Apr 19, 2022
Follow up rails/rails#44354.

Also, the deprecated warning for `to_s(:db)` is `to_fs(:db)` instead of `to_formatted_s(:db)`.

> DateTime#to_s(:db) is deprecated. Please use DateTime#to_fs(:db) instead.
koic added a commit to koic/rails-style-guide that referenced this pull request Apr 20, 2022
Follow up rails/rails#44354.

Also, the deprecated warning for `to_s(:db)` is `to_fs(:db)` instead of `to_formatted_s(:db)`.

> DateTime#to_s(:db) is deprecated. Please use DateTime#to_fs(:db) instead.
gbp added a commit to mysociety/alaveteli that referenced this pull request Apr 28, 2022
Use replacement `#to_fs` instead. Fixes deprecation warnings:
```
TimeWithZone#to_s(:db) is deprecated. Please use TimeWithZone#to_fs(:db) instead.
```

See rails/rails#44354
goldapple911 added a commit to goldapple911/rails-style-guide that referenced this pull request Aug 15, 2023
Follow up rails/rails#44354.

Also, the deprecated warning for `to_s(:db)` is `to_fs(:db)` instead of `to_formatted_s(:db)`.

> DateTime#to_s(:db) is deprecated. Please use DateTime#to_fs(:db) instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants