Skip to content

Conversation

y-yagi
Copy link
Member

@y-yagi y-yagi commented Oct 22, 2023

Detail

In Rails 7.1.1, using Date#to_fs with an un-exist format, shows the deprecation warning like the following.

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.

So I thought this was just a typo and fixed to use #to_s like other classes.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

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.
Copy link
Contributor

@aashishpsaini aashishpsaini left a comment

Choose a reason for hiding this comment

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

Good Spot. Thanks for doing this change.

@kamipo kamipo merged commit 5534a22 into rails:main Oct 22, 2023
kamipo added a commit that referenced this pull request Oct 22, 2023
Don't use deprecated `#to_default_s` in `Date#to_fs`
@y-yagi y-yagi deleted the donot-use-deprecated-to_default_s branch October 22, 2023 20:07
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.

3 participants