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 invalid date issue without catch or raise exception #289

Merged
merged 2 commits into from
Sep 4, 2015

Conversation

halan
Copy link
Contributor

@halan halan commented Sep 3, 2015

This solve #267 without catch generic exceptions or any other. I use the same test at the other PR.

@pedrofelipe
Copy link

👍

3 similar comments
@matheusazzi
Copy link

👍

@cefigueiredo
Copy link

👍

@brunoskonrad
Copy link

👍

@iagomoreira
Copy link

smooth 👍

@brnrdog
Copy link

brnrdog commented Sep 3, 2015

nice 👍

@luizvarela
Copy link

👍

1 similar comment
@romulostorel
Copy link

👍

@@ -24,10 +24,12 @@ def call(params)

private
def params_to_date(year, month, day, hour, minute)
return nil if [year, month, day].any?(&:blank?)
if [year, month, day].any?(&:blank?) || !Date.valid_date?(*[year, month, day].map(&:to_i))

Choose a reason for hiding this comment

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

You are generating the same array twice, can you refactor and reuse the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think about it, I just try to solve the problem with minimum code, but I will do it, above have the same array too.

Copy link

Choose a reason for hiding this comment

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

Blank strings become 0 when coerced via to_i. Given that any 0 is understood as an invalid date, what do you think about skipping the blank? check? Maybe I'm missing something?

@waldyr
Copy link

waldyr commented Sep 3, 2015

👎

return nil if [year, month, day].any?(&:blank?)
if [year, month, day].any?(&:blank?) || !Date.valid_date?(*[year, month, day].map(&:to_i))
return nil
end

if hour.blank? && minute.blank?

Choose a reason for hiding this comment

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

if you are handling dates, why are you concerned about hour and minute?

@apotonick
Copy link
Member

Haha, great but since when do we have this 👍 on my gems?! 😆

@apotonick
Copy link
Member

Cool, so this catches invalid dates without an exception? That's great! Any concerns?

@halan
Copy link
Contributor Author

halan commented Sep 4, 2015

Yeah, it will. And no concerns, it's ruby 1.8 compatible. It will return nil if receives invalid date, instead ArgumentError raised by Date.new or Time.new

@halan
Copy link
Contributor Author

halan commented Sep 4, 2015

I just put the tests from #267.

@apotonick
Copy link
Member

@halan But here you test invalid dates: https://github.com/apotonick/reform/pull/289/files#diff-ad5370b7e7280e5aeb58a9412a4ade3bR20 and I can't see any rescue in your code.

Please join https://gitter.im/trailblazer/chat for a quick chat! 🍻

@apotonick apotonick merged commit 81de44c into trailblazer:master Sep 4, 2015
@brunoskonrad
Copy link

👏

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.