rails: date_select causing wrong date when using discard_year and include_blank
When using discard_year together with include_blank the date_helper sets year to “1” using a hidden field. That somehow causes the saved date value to be altered in a way, that the “day” part of the date increases by two …
So choosing “january” “1” from the two selects saves the date “0001-01-03” instead of “0001-01-01”
But if the value of the year part is set anything from 201 upto 300 or 1583 upto 2017 the day and month parts remains as entered, which makes no sense to me.
Steps to reproduce
rails new app_test_discard_year
cd app_test_discard_year/
rails generate scaffold test_day day:date
rails db:migrate
Add { discard_year: true, include_blank: true }
to the date_select in
app/views/test_days/_form.html.erb
so it looks like this <%= f.date_select :day, { discard_year: true, include_blank: true } %>
Start server and try creating a new “Test Day” choosing january 1st and save.
Rails 5.0.2 ruby 2.4.0p0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 15 (2 by maintainers)
Rails is 5.1.4 already and problem is still there…
@marcosdemelo sorry, I just checked this thread. If the error is reproducible in current rails version please go ahead and open an issue!
I took a stab at it here https://github.com/rails/rails/pull/29651 😄