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

fix Date.strptime monkeypatch #217

Merged
merged 1 commit into from
Sep 10, 2019

Conversation

nerdrew
Copy link
Contributor

@nerdrew nerdrew commented Oct 11, 2017

See #108, #115, #116, #132.

@nerdrew
Copy link
Contributor Author

nerdrew commented Oct 11, 2017

One of the dependencies doesn't seem to support ruby 1.9.3 anymore. Thoughts on removing support for 1.9 in .travis.yml?

@tom-lord
Copy link
Contributor

I'd vote to remove it (and bump the gem minor version). It can't support old rubies forever!

@kachick kachick mentioned this pull request Nov 3, 2017
def test_date_strptime_with_invalid_date
begin
Date.strptime('', '%Y-%m-%d')
rescue ArgumentError => e
Copy link

Choose a reason for hiding this comment

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

@@ -48,7 +48,17 @@ def strptime_with_mock_date(str = '-4712-01-01', fmt = '%F', start = Date::ITALY
"supports Date::ITALY for the start argument."
end

Time.strptime(str, fmt).to_date
d = Date._strptime(str, fmt) || Date.strptime_without_mock_date(str, fmt)
Copy link

Choose a reason for hiding this comment

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

Can you please explain why is there are _strptime or strptime_without_mock_date, and not just strptime_without_mock_date used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on the docs https://ruby-doc.org/stdlib-2.6/libdoc/date/rdoc/Date.html#method-c-_strptime returns a hash instead of a date object. I think I was thinking I didn't need the actual date object, but I wrote that too long ago to remember.

It looks like strptime actually calls _strptime internally, so we could probably just go with strptime_without_mock_date. Do the tests still pass that way?

cc #242 <--- seems better to merge

@kwerle kwerle mentioned this pull request Jun 15, 2019
@travisjeffery travisjeffery merged commit 6dee236 into travisjeffery:master Sep 10, 2019
@travisjeffery
Copy link
Owner

Merged the equivalent in #242 based on this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants