Skip to content

Commit bbe591d

Browse files
committed
Don't use deprecated #to_default_s in Date#to_fs
In Rails 7.1.1, using `Date#to_fs` with an un-exist format, shows the deprecation warning like the following. ```ruby Date.current.to_fs(:doesnt_exist) => DEPRECATION WARNING: to_default_s is deprecated and will be removed from Rails 7.2 (use to_s instead) (called from <main> at ./bin/rails:4) ``` But other date-time-related classes still allow to use this. https://github.com/rails/rails/blob/6f6c211f4781e7bda63e5f47089f9d2612dc0a52/activesupport/lib/active_support/core_ext/time/conversions.rb#L57 https://github.com/rails/rails/blob/6f6c211f4781e7bda63e5f47089f9d2612dc0a52/activesupport/lib/active_support/core_ext/date_time/conversions.rb#L39 So I thought this was just a typo and fixed to use `#to_s` like other classes.
1 parent 6f6c211 commit bbe591d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

activesupport/lib/active_support/core_ext/date/conversions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def to_fs(format = :default)
5252
strftime(formatter)
5353
end
5454
else
55-
to_default_s
55+
to_s
5656
end
5757
end
5858
alias_method :to_formatted_s, :to_fs

activesupport/test/core_ext/date_ext_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_to_fs
3737
assert_equal "2005-02-21", date.to_fs(:inspect)
3838
assert_equal "21 Feb 2005", date.to_fs(:rfc822)
3939
assert_equal "2005-02-21", date.to_fs(:iso8601)
40+
assert_equal date.to_s, date.to_fs(:doesnt_exist)
4041
assert_equal "21 Feb", date.to_formatted_s(:short)
4142
end
4243

0 commit comments

Comments
 (0)