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

Added aliases for prev_year, prev_month, and prev_week in Time and Date calculations #4284

Merged
merged 1 commit into from
Feb 28, 2012
Merged

Added aliases for prev_year, prev_month, and prev_week in Time and Date calculations #4284

merged 1 commit into from
Feb 28, 2012

Conversation

mdespuits
Copy link

As I was working with some time methods, I noticed that using the word last made more sense as it is generally how it is thought of. I have added aliases for these three methods last_year, last_month, and last_week.

@waseem
Copy link
Contributor

waseem commented Jan 22, 2012

👍 Some tests would have been nice.

@mdespuits
Copy link
Author

What tests would I need to write? I provided some already...

@waseem
Copy link
Contributor

waseem commented Jan 23, 2012

@mattdbridges I apologize. Perhaps I was too sleepy to see those tests. :)

@vijaydev
Copy link
Member

The AS guide needs to be updated. cc: @fxn

@mdespuits
Copy link
Author

@vijaydev How do I go about doing this? or does someone else need to do this?

@vijaydev
Copy link
Member

@mattdbridges It's expected to be done as part of the patch. You would need to update this file: https://github.com/rails/rails/blob/master/railties/guides/source/active_support_core_extensions.textile. This will reflect in http://edgeguides.rubyonrails.org/active_support_core_extensions.html once the PR is merged.

@fxn
Copy link
Member

fxn commented Feb 14, 2012

@mattdbridges I like the aliases.

We have those also in Date, could you please add them also to Date? That way DateTime will also have them via inheritance.

Then, you'd also need to edit the file railties/guides/source/active_support_core_extensions.textile and document the aliases in the corresponding section of each of the three classes somehow.

@ghost ghost assigned fxn Feb 14, 2012
@mdespuits
Copy link
Author

Thanks @vijaydev and @fxn. I'll work on these as soon as I can and make push them up.

@mdespuits
Copy link
Author

@fxn Correct me if I'm wrong, but it looks like I have added these aliases to Date already. These would be in active_support/core_ext/date/calculations.rb, am I right?

@mdespuits
Copy link
Author

Ignore the last comment. I have the prev_week method in Date already, but where would the aliases for last_month or last_year go since they are not actually defined in Date?

@fxn
Copy link
Member

fxn commented Feb 17, 2012

They have been removed in master because they come with Ruby 1.9. Previous versions defined them for forward compatibility.

@mdespuits
Copy link
Author

Ah, thanks for the clarification.

@mdespuits
Copy link
Author

Is this what you were looking for?

@@ -182,6 +182,13 @@ def prev_week(day = :monday)
result = (self - 7).beginning_of_week + DAYS_INTO_WEEK[day]
self.acts_like?(:time) ? result.change(:hour => 0) : result
end
alias :last_week, :prev_week
Copy link
Member

Choose a reason for hiding this comment

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

Why alias here and alias_method for the other two? Moreover, this syntax is incorrect for alias. It should be alias :last_week :prev_week

Copy link
Author

Choose a reason for hiding this comment

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

I used alias here as I noticed many other other aliases used it instead of alias_method. I was unsure of what the convention was, so I went with what I saw.

Copy link
Author

Choose a reason for hiding this comment

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

I am more than willing to change it to whatever you recommend.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough, but you've to fix the error then. Also in that case, just to be consistent within this PR, please change the two alias_methods below into aliases.

@vijaydev
Copy link
Member

Can you please remove the unrelated merge commits, and squash all your commits into one?

@mdespuits
Copy link
Author

@vijaydev, Yes, but how do I do that exactly? I am familiar with git rebase -i, but couldn't that potentially harm the references when I push to a remote repo, as in this case?

@vijaydev
Copy link
Member

Yes, you've to use interactive rebase rebase -i and squash. Since this PR is created from a topic branch, you can do a force push git push -f which will overwrite the commits in this PR with the one you push. Remember to remove the unrelated commits.

In general, do not try to make a topic branch up to date with master by pulling in from master. Just work on your commits, squash and push (with force pushing whenever necessary).

@mdespuits
Copy link
Author

@vijaydev Thanks for the tip. Actually, I never merged from the master. I am not sure how that unrelated commit ended up in there. Any thoughts on how to get it out of this PR?

@mdespuits
Copy link
Author

Actually, it's not there anymore. I'll push my squashed commits.

fxn added a commit that referenced this pull request Feb 28, 2012
Added aliases for prev_year, prev_month, and prev_week in Time and Date calculations
@fxn fxn merged commit 699ba8a into rails:master Feb 28, 2012
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