Skip to content
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

Return correct date in ActiveModel for time to date conversions #29651

Merged
merged 1 commit into from Feb 18, 2019

Conversation

Sayanc93
Copy link
Contributor

@Sayanc93 Sayanc93 commented Jul 1, 2017

time.to_date conversion happens considering leap years in Ruby.
So a conversion of Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"}) or 0001-01-01 00:00:00 UTC results in saving the date in DB as Mon, 03 Jan 0001.
Which might seem weird on the user level, hence falling back to parsing on string level resolves this data mismatch respecting the parameters passed
Fixes #28521

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

activemodel/lib/active_model/type/date.rb Outdated Show resolved Hide resolved
activemodel/CHANGELOG.md Outdated Show resolved Hide resolved
activemodel/CHANGELOG.md Outdated Show resolved Hide resolved
@Sayanc93 Sayanc93 force-pushed the return-correct-date branch 2 times, most recently from 15fcba3 to 19238e6 Compare July 21, 2017 00:19
@Sayanc93
Copy link
Contributor Author

r? @kamipo

@rails-bot rails-bot assigned kamipo and unassigned schneems Aug 21, 2017
time.to_date conversion happens considering leap years
so a conversion of "Day.new({'day(1i)'=>'1', 'day(2i)'=>'1', 'day(3i)'=>'1'})" results in saving the date as Mon, 03 Jan 0001
which might seem weird on the user level, hence falling back to parsing on string level resolves this data mismatch
Fixes rails#28521
@kamipo kamipo merged commit eb73dfc into rails:master Feb 18, 2019
kamipo added a commit that referenced this pull request Feb 18, 2019
Return correct date in ActiveModel for time to date conversions
kamipo added a commit that referenced this pull request Feb 19, 2019
Return correct date in ActiveModel for time to date conversions
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.

date_select causing wrong date when using discard_year and include_blank
5 participants