Skip to content

date_select causing wrong date when using discard_year and include_blank #28521

@grantzau

Description

@grantzau

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 } %>

http://localhost:3000/test_days

Start server and try creating a new "Test Day" choosing january 1st and save.

Rails 5.0.2
ruby 2.4.0p0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions