From 8c3f4bec1fc6b50025f256f5244acbb8e892c9ee Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Fri, 4 May 2012 15:18:59 +0100 Subject: added beginning_of_hour support to core_ext calculations for Time and DateTime --- .../lib/active_support/core_ext/date_time/calculations.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/date_time/calculations.rb') 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 0e5aa5af10..020fa1a06d 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -91,6 +91,17 @@ class DateTime change(:hour => 23, :min => 59, :sec => 59) end + # Returns a new DateTime representing the start of the hour (hh:00:00) + def beginning_of_hour + change(:min => 0) + end + alias :at_beginning_of_hour :beginning_of_hour + + # Returns a new DateTime representing the end of the hour (hh:59:59) + def end_of_hour + change(:min => 59, :sec => 59) + end + # Adjusts DateTime to UTC by adding its offset value; offset is set to 0 # # Example: -- cgit v1.2.3