This project is archived and is in readonly mode.
Add weeks_ago helper
-
Rob Zolkos
- Title changed from Add weeks_ago helper to [PATCH] Add weeks_ago helper
-
Steven Hancock
Seems useful, and consistent with the date features Rails already has.
All tests pass for me with (rvm) ruby-1.8.7-p299, ree-1.8.7-2010.02 and ruby-1.9.2-rc2.
+1
-
John Timms
This feature would be very useful, I was about to create a request for it myself. Thanks for your work, Rob!
-
xds2000
rvm ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0], MBARI 0x6770, Ruby Enterprise Edition 2010.02
xiaodeshi:~/projects/rails[weeks_ago*]$ git am < weeks_ago.diff
Applying: weeks_ago
error: patch failed: activesupport/lib/active_support/core_ext/date/calculations.rb:7
error: activesupport/lib/active_support/core_ext/date/calculations.rb: patch does not apply
error: patch failed: activesupport/test/core_ext/date_ext_test.rb:26
error: activesupport/test/core_ext/date_ext_test.rb: patch does not apply
Patch failed at 0001 weeks_ago -
xds2000
just test in rails master brach in github.So i don't clear this patch can suite any version rails.
-
Steven Hancock
When the patch was submitted it applied cleanly to Rails master branch and all tests passed (for me anyway) with 3 different versions of Ruby. I can't say why nobody else tested it or committed it at that time, most likely it just got overlooked.. but you tested it a month later (almost to the day), with an understanding of how diff/patch work and how much daily activity the Rails repo gets I would probably die of shock if I tried to apply a month old patch and it applied cleanly.
-
Rob Zolkos
I'll update this patch to work with latest master later today and update the ticket accordingly.
-
Rob Zolkos
Attached is the updated weeks_ago.diff patch which applies cleanly to the current rails master and tests ok. Hope this gets looked at :)
-
Jeff Kreeftmeijer
- State changed from new to open
- Title changed from [PATCH] Add weeks_ago helper to Add weeks_ago helper
- Tag changed from activesupport, date, helpers to activesupport, date, helpers, patch
- Importance changed from to Low
+1
Nice one. Patch applies to master cleanly and the tests pass.
Please remember to use the "patch" tag instead of prefixing the ticket title with "[PATCH]" to make sure patched tickets end up in the open patches bin. :)
-
Aditya Sanghi
- Milestone set to 3.x
- Assigned user set to Santiago Pastorino
+1 i think weeks_ago is fairly useful.
-
Santiago Pastorino
- Assigned user changed from Santiago Pastorino to Xavier Noria
-
Xavier Noria
Looks good. Could you please add this stuff to the Active Support Core Extensions guide and submit a new patch including that?
-
Rob Zolkos
New patch that includes additions to the guide as requested.
-
Xavier Noria
Rob, I have had a look at this. weeks_ago seems fine to me, but I think one would expect prev_week to be symmetric with the existing next_week helper in Active Support (see its docs in the guide for example).
Also, are you sure Ruby 1.9 defines Date#prev_week?
-
Rob Zolkos
Here is a new patch with some fixes. Not sure what you mean by prev_week and next_week being symmetric? They work slightly differently so thought they needed to be separate in the guide. Happy to lump them together however. Let me know :)
-
Xavier Noria
I mean, next_week is not defined to be weeks_since(1), it expects a day of the week as a symbol etc. Since next_week exists and it is defined that way, one would expect prev_week to be similar but about the previous week.
-
Rob Zolkos
I've redone prev_week to behave similar to next_week. However, instead of the default day being Monday, I have made it so that it is the same day as the receiver, meaning if its currently Thursday then it will return the date last Thursday (by default). This can be overriden by passing in the day name as a symbol (eg :monday) just like in next_week. I can easily change this to be exactly like the bahaviour of next_week, however I feel that by default, most will want to know the date exactly one week ago from the current day.
Guides have been updated too.
This is my first patch so I'm learning heaps :)
-
Xavier Noria
Good!
I agree that it is a better default, and it would be also a better default for next_week.
But since we cannot change next_week right now, I think it would still be better that they are consistent in this regard. They should have the same default. And the documentation for both should be very similar in consequence, that's an indicator (rather than needing warnings: "careful! my other friend has a different default").
Thanks for your effort with this patch Rob, I think we are close :).
-
Rob Zolkos
new patch attached, with prev_week default like next_week and documented in the same place in similar ways in the guides.
-
Elad Meidar
I hate to be a party /smasher/ but shouldn't all those helpers be joined into one?, something like:
DateTime.now.ago(10, :minutes)
and if i think about it:
DateTime.now - 10.minutes
is way more readable.
-
Xavier Noria
Elad, yeah, that one already exists it is called Date#advance, see http://guides.rubyonrails.org/active_support_core_extensions.html#a....
There is also DateTime#advance: http://guides.rubyonrails.org/active_support_core_extensions.html#d... (Note that DateTime does not do DST), and Time#advance (Time does, but its domain depends on the machine).
These next* prev* are just convenience shortcuts. Well, in the case of next_week not really because it involves more computations.
-
Xavier Noria
I've extracted the hash with offsets to avoid its duplication, also implemented the new methods for Time. Gonna push tonight.
-
Repository
- State changed from open to committed
(from [bc1bcddede0c300e9c88f76a66a152814b734981]) implements weeks_ago and prev_week for Date/DateTime/Time [#5122 state:committed] http://github.com/rails/rails/commit/bc1bcddede0c300e9c88f76a66a152...
-
Xavier Noria
- State changed from committed to open
-
Xavier Noria
- State changed from open to committed
-
Ryan Bigg
- Tag changed from sheepskin boots, activesupport, date, helpers, patch to activesupport date helpers patch
Automatic cleanup of spam.
