aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time/calculations.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-05-04 15:34:11 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-05-04 15:34:11 -0700
commitfecfd61c227376d8d07f9e4ea638df496c2b08dc (patch)
tree893f05a201152e721152074279ba14faa25a1494 /activesupport/lib/active_support/core_ext/time/calculations.rb
parentdb6a399c8a7ddd3457fcb1aac388fd4d5fb7e748 (diff)
parent8c3f4bec1fc6b50025f256f5244acbb8e892c9ee (diff)
downloadrails-fecfd61c227376d8d07f9e4ea638df496c2b08dc.tar.gz
rails-fecfd61c227376d8d07f9e4ea638df496c2b08dc.tar.bz2
rails-fecfd61c227376d8d07f9e4ea638df496c2b08dc.zip
Merge pull request #6156 from mjtko/feature-beginning_of_hour
Beginning and end of hour support 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 1434e186c3..a0f610d60c 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -257,6 +257,21 @@ class Time
)
end
+ # Returns a new Time representing the start of the hour (x:00)
+ def beginning_of_hour
+ change(:min => 0)
+ end
+ alias :at_beginning_of_hour :beginning_of_hour
+
+ # Returns a new Time representing the end of the hour, x:59:59.999999 (.999999999 in ruby1.9)
+ def end_of_hour
+ change(
+ :min => 59,
+ :sec => 59,
+ :usec => 999999.999
+ )
+ end
+
# Returns a new Time representing the start of the month (1st of the month, 0:00)
def beginning_of_month
#self - ((self.mday-1).days + self.seconds_since_midnight)