-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Conversation
#to_formatted_s is too cumbersome.
There was a problem hiding this 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
I'm taking over this PR to fix the test/doc problem. |
Make #to_fs the default replacement for #to_s(:format)
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.
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.
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
rails/rails#43772 rails/rails#44354 Signed-off-by: Takuya Noguchi <[email protected]>
rails/rails#43772 rails/rails#44354 Signed-off-by: Takuya Noguchi <[email protected]>
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.
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.
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
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.
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.