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

tiny refactoring of date_helper #4739

Merged
merged 1 commit into from
Jan 29, 2012
Merged

Conversation

nashby
Copy link
Contributor

@nashby nashby commented Jan 28, 2012

use :default option with translate method instead of condition
simplify separator method

@@ -854,7 +854,7 @@ def date_order
end

def translated_date_order
date_order = I18n.translate(:'date.order', :locale => @options[:locale]) || []
date_order = Array(I18n.translate(:'date.order', :locale => @options[:locale]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't worth all the work that Kernel#Array does just to avoid || [], I like better the old version

Copy link
Member

Choose a reason for hiding this comment

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

I think that is better to use the :default option of translate method

I18n.translate(:'date.order', :locale => @options[:locale], :default => [])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rafaelfranca I've got these errors with :default option: https://gist.github.com/9a8634d407018d38d112
@spastorino reverted to old version.

Copy link
Member

Choose a reason for hiding this comment

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

@nashby you need to update the mocha expectation in the tests too. These lines 106 118 123

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, I see. Thanks.
So, @spastorino, what do you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree with @rafaelfranca :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. Thanks guys for helping out with this!

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for improve the Rails code.

use :default option with translate method instead of condition
simplify separator method
spastorino added a commit that referenced this pull request Jan 29, 2012
@spastorino spastorino merged commit ec4440f into rails:master Jan 29, 2012
when :second
@options[:include_seconds] ? @options[:time_separator] : ""
when :minute, :second
@options[:"discard_#{type}"] ? "" : @options[:time_separator]
Copy link
Member

Choose a reason for hiding this comment

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

💣 These two can't be clubbed together. discard_minute, include_seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, but what do you mean?

Copy link
Member

Choose a reason for hiding this comment

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

Oh crap! You've changed the order of the ternary. I'm sorry. I read it wrongly as: you can't be returning @options[:time_separator] for the discard_seconds option.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm. Thinking in this way the behavior was changed. Before this change the separator only is used if the option :include_seconds is true. Now the separator is not used if the option :discard_second is true. This mean that the separator is always used unless you had used the :discard_second option. This need to be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I think discard_second == not include_seconds or I'm missing something?https://github.com/nashby/rails/blob/master/actionpack/lib/action_view/helpers/date_helper.rb#L701

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you are right. Sorry

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.

None yet

4 participants