From 1b6bbb09532e164bf373c1cd273e4ec9062b9e56 Mon Sep 17 00:00:00 2001 From: Anatoli Makarevich Date: Fri, 7 Jun 2013 18:37:41 +0400 Subject: Added Time#middle_of_day Added middle_of_day method to Date and DateTime --- .../lib/active_support/core_ext/date_time/calculations.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/date_time') 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 937567440b..b718ae10c3 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -107,6 +107,16 @@ class DateTime alias :at_midnight :beginning_of_day alias :at_beginning_of_day :beginning_of_day + # Returns a new DateTime representing the middle of the day (12:00) + def middle_of_day + change(:hour => 12) + end + alias :midday :middle_of_day + alias :noon :middle_of_day + alias :at_midday :middle_of_day + alias :at_noon :middle_of_day + alias :at_middle_of_day :middle_of_day + # Returns a new DateTime representing the end of the day (23:59:59). def end_of_day change(:hour => 23, :min => 59, :sec => 59) -- cgit v1.2.3