From 1b32a305df40829c650a5254441eaec491e9f086 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 4 Jun 2007 22:00:53 +0000 Subject: Add Date#since, ago, beginning_of_day, and end_of_day. Date + seconds works now. Closes #8575. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6937 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_support/core_ext/date/calculations.rb | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 5c4ed65b28..637c9ea02a 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -23,6 +23,32 @@ module ActiveSupport #:nodoc: end end + # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) + # and then subtracts the specified number of seconds + def ago(seconds) + to_time.since(-seconds) + end + + # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) + # and then adds the specified number of seconds + def since(seconds) + to_time.since(seconds) + end + alias :in :since + + # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) + def beginning_of_day + to_time + end + alias :midnight :beginning_of_day + 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 end of the day (23:59:59) + def end_of_day + to_time.end_of_day + end + def plus_with_duration(other) #:nodoc: if ActiveSupport::Duration === other other.since(self) -- cgit v1.2.3