diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2011-06-13 18:54:15 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-06-13 18:56:06 +0200 |
commit | d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e (patch) | |
tree | 167db89b84e1f443c24a3a73961b5f004104c9e0 /activesupport/lib | |
parent | b12c2e4ebb85170467ac250219557d631c842d8d (diff) | |
download | rails-d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e.tar.gz rails-d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e.tar.bz2 rails-d6cc0e56bdf1d657f16e5c4026f53d0a4e2dd37e.zip |
Added Time#whole_day/week/quarter/year as a way of generating ranges (example: Event.where(created_at: Time.now.whole_week)) [DHH]
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 00fda2b370..54e16a9fb7 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -226,7 +226,7 @@ class Time end alias :at_end_of_quarter :end_of_quarter - # Returns a new Time representing the start of the year (1st of january, 0:00) + # Returns a new Time representing the start of the year (1st of january, 0:00) def beginning_of_year change(:month => 1, :day => 1, :hour => 0) end @@ -248,6 +248,31 @@ class Time advance(:days => 1) end + # Returns a Range representing the whole day of the current time. + def whole_day + beginning_of_day..end_of_day + end + + # Returns a Range representing the whole week of the current time. + def whole_week + beginning_of_week..end_of_week + end + + # Returns a Range representing the whole month of the current time. + def whole_month + beginning_of_month..end_of_month + end + + # Returns a Range representing the whole quarter of the current time. + def whole_quarter + beginning_of_quarter..end_of_quarter + end + + # Returns a Range representing the whole year of the current time. + def whole_year + beginning_of_year..end_of_year + end + def plus_with_duration(other) #:nodoc: if ActiveSupport::Duration === other other.since(self) |