diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-29 10:25:06 -0700 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-29 10:25:06 -0700 |
commit | c90105613188a088b9834a701e3ab15fa3e92bad (patch) | |
tree | 031b3b717ab637f58961d49b4fd437cc5996bca2 /activesupport/lib | |
parent | b51786d26e8262534f043c5c614b9e04cd33dbc1 (diff) | |
parent | 1b6bbb09532e164bf373c1cd273e4ec9062b9e56 (diff) | |
download | rails-c90105613188a088b9834a701e3ab15fa3e92bad.tar.gz rails-c90105613188a088b9834a701e3ab15fa3e92bad.tar.bz2 rails-c90105613188a088b9834a701e3ab15fa3e92bad.zip |
Merge pull request #10879 from makaroni4/master
Added Time#middle_of_day method
Diffstat (limited to 'activesupport/lib')
3 files changed, 30 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index eddb1b851f..af048d0c85 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -69,6 +69,16 @@ class Date alias :at_midnight :beginning_of_day alias :at_beginning_of_day :beginning_of_day + # Converts Date to a Time (or DateTime if necessary) with the time portion set to the middle of the day (12:00) + def middle_of_day + in_time_zone.middle_of_day + 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 + # Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59) def end_of_day in_time_zone.end_of_day 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 7d4f716bb6..c288a1f9bd 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -99,6 +99,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) diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index c739cce223..6e0af0db4d 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -142,6 +142,16 @@ class Time alias :at_midnight :beginning_of_day alias :at_beginning_of_day :beginning_of_day + # Returns a new Time 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 Time representing the end of the day, 23:59:59.999999 (.999999999 in ruby1.9) def end_of_day change( |