diff options
author | Gagan Awhad <gagan.awhad@desiringgod.org> | 2013-02-21 14:22:50 -0600 |
---|---|---|
committer | Gagan Awhad <gagan.awhad@desiringgod.org> | 2013-02-21 16:14:16 -0600 |
commit | 6f380d37788a562c13d0d68b1d3f28f8a6f4b3ec (patch) | |
tree | 3f7a276045f28f46cfb3c0e40ca1edce4593eddf /activesupport/lib/active_support | |
parent | 389397952460d09218bb407be1142e0b62cf3f4f (diff) | |
download | rails-6f380d37788a562c13d0d68b1d3f28f8a6f4b3ec.tar.gz rails-6f380d37788a562c13d0d68b1d3f28f8a6f4b3ec.tar.bz2 rails-6f380d37788a562c13d0d68b1d3f28f8a6f4b3ec.zip |
Added beginning_of_minute support to core_ext calculations for Time and DateTime
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 12 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 15 |
2 files changed, 27 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 1d3682eaf2..82cc46aa37 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -123,6 +123,18 @@ class DateTime change(:min => 59, :sec => 59) end alias :at_end_of_hour :end_of_hour + + # Returns a new DateTime representing the start of the hour (hh:mm:00). + def beginning_of_minute + change(:sec => 0) + end + alias :at_beginning_of_minute :beginning_of_minute + + # Returns a new DateTime representing the end of the minute (hh:mm:59). + def end_of_minute + change(:sec => 59) + end + alias :at_end_of_minute :end_of_minute # Adjusts DateTime to UTC by adding its offset value; offset is set to 0. # diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 1f95f62229..c18169fab5 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -188,6 +188,21 @@ class Time end alias :at_end_of_hour :end_of_hour + # Returns a new Time representing the start of the hour (x:xx:00) + def beginning_of_minute + change(:sec => 0) + end + alias :at_beginning_of_minute :beginning_of_minute + + # Returns a new Time representing the end of the hour, x:59:59.999999 (.999999999 in ruby1.9) + def end_of_minute + change( + :sec => 59, + :usec => Rational(999999999, 1000) + ) + end + alias :at_end_of_minute :end_of_minute + # Returns a Range representing the whole day of the current time. def all_day beginning_of_day..end_of_day |