diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-21 14:46:33 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-21 14:46:33 +0000 |
commit | 25f8a25c3ea107dcd0688307ac0ce19c4306f6b4 (patch) | |
tree | e2b00181d72285d9b757598de41a64e75d8f87c9 /activesupport/lib | |
parent | 637642c8b85707779af45f80a104dd84be6a904d (diff) | |
download | rails-25f8a25c3ea107dcd0688307ac0ce19c4306f6b4.tar.gz rails-25f8a25c3ea107dcd0688307ac0ce19c4306f6b4.tar.bz2 rails-25f8a25c3ea107dcd0688307ac0ce19c4306f6b4.zip |
Added next_week and made beginning_of_week be a Monday, not a Sunday
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@733 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index f31c282434..c62a2447e8 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -53,13 +53,19 @@ module ActiveSupport #:nodoc: end end - # Returns a new Time representing the "start" of this week (sunday, 0:00) + # Returns a new Time representing the "start" of this week (Monday, 0:00) def beginning_of_week - (self - self.wday.days).midnight + (self - self.wday.days).midnight + 1.day end - alias :sunday :beginning_of_week + alias :monday :beginning_of_week alias :at_beginning_of_week :beginning_of_week + # Returns a new Time representing the start of the given day in next week (default is Monday). + def next_week(day = :monday) + days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6} + since(1.week).beginning_of_week.since(days_into_week[day].day).change(:hour => 0) + end + # Returns a new Time representing the start of the day (0:00) def beginning_of_day self - self.seconds_since_midnight |