aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time/calculations.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-02-21 14:22:36 -0800
committerAndrew White <andyw@pixeltrix.co.uk>2013-02-21 14:22:36 -0800
commitb5df957af122991360f273eca5d2a3bf710e40d6 (patch)
treee796118c236432b0a21ecae1096bed728f479fa5 /activesupport/lib/active_support/core_ext/time/calculations.rb
parent4b48a75230615edf72c9701da86413e09e0dc2fe (diff)
parent6f380d37788a562c13d0d68b1d3f28f8a6f4b3ec (diff)
downloadrails-b5df957af122991360f273eca5d2a3bf710e40d6.tar.gz
rails-b5df957af122991360f273eca5d2a3bf710e40d6.tar.bz2
rails-b5df957af122991360f273eca5d2a3bf710e40d6.zip
Merge pull request #9365 from gaganawhad/core-ext-beginning-of-minute
Added beginning_of_minute support to core_ext calculations for Time and DateTime
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/calculations.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb15
1 files changed, 15 insertions, 0 deletions
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