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

String to date conversions use current century #14666

Closed
wants to merge 1 commit into from
Closed

String to date conversions use current century #14666

wants to merge 1 commit into from

Conversation

kylemacey
Copy link

Previously, converting a String to Date with a 2 digit year would assume a year
between AD00 and AD99. As most software does not deal with these years, and it
is unlikely that this is considered expected behavior, String#to_date and
String#to_datetime now use the same defaults as Date#parse.

@rafaelfranca
Copy link
Member

cc @pixeltrix

Previously, converting a String to Date with a 2 digit year would assume a year
between AD00 and AD99. As most software does not deal with these years, and it
is unlikely that this is considered expected behavior, `String#to_date` and
`String#to_datetime` now use the same defaults as `Date#parse`.
@claudiob
Copy link
Member

I think this change makes sense, since it matches the default behavior of Ruby's stdlib.

@pixeltrix I can go on and rebase this commit against current master if you are 👍

@solojavier
Copy link

Any update on this? @claudiob @pixeltrix

@kylemacey
Copy link
Author

I can rebase again (and remove my whitespace changes) if need be.

@pixeltrix
Copy link
Contributor

I think I've said before that String#to_date and friends are not intended to be generic human text input parsers for a field in a form - there's not enough error checking for that and changing the behaviour for existing apps is also a reason not to merge this. There is now a ActiveSupport::TimeZone#strptime in Rails 5 that's available if you need to parse custom formats.

@kylemacey thanks for the PR, sorry I can't merge it.

@pixeltrix pixeltrix closed this Aug 9, 2016
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.

None yet

5 participants