aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date
diff options
context:
space:
mode:
authorPablo Herrero <pablodherrero@gmail.com>2015-04-23 16:33:23 -0300
committerPablo Herrero <pablodherrero@gmail.com>2015-05-04 08:06:52 -0300
commitbbe7b7f504ea5010712ee37d84f8c86682dd14f8 (patch)
treebaead3282de4b044960862f81900fddcb3982105 /activesupport/lib/active_support/core_ext/date
parent21c74bd769f6c873453e9244b0de7ced40a532be (diff)
downloadrails-bbe7b7f504ea5010712ee37d84f8c86682dd14f8.tar.gz
rails-bbe7b7f504ea5010712ee37d84f8c86682dd14f8.tar.bz2
rails-bbe7b7f504ea5010712ee37d84f8c86682dd14f8.zip
Replace use of alias chains with prepend at core_ext/date
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb34
-rw-r--r--activesupport/lib/active_support/core_ext/date/operators.rb16
2 files changed, 18 insertions, 32 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index c60e833441..86d7fa1abf 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -1,12 +1,13 @@
require 'date'
-require 'active_support/duration'
require 'active_support/core_ext/object/acts_like'
require 'active_support/core_ext/date/zones'
+require 'active_support/core_ext/date/operators'
require 'active_support/core_ext/time/zones'
require 'active_support/core_ext/date_and_time/calculations'
class Date
include DateAndTime::Calculations
+ prepend ActiveSupport::DateOperators
class << self
attr_accessor :beginning_of_week_default
@@ -85,26 +86,6 @@ class Date
end
alias :at_end_of_day :end_of_day
- def plus_with_duration(other) #:nodoc:
- if ActiveSupport::Duration === other
- other.since(self)
- else
- plus_without_duration(other)
- end
- end
- alias_method :plus_without_duration, :+
- alias_method :+, :plus_with_duration
-
- def minus_with_duration(other) #:nodoc:
- if ActiveSupport::Duration === other
- plus_with_duration(-other)
- else
- minus_without_duration(other)
- end
- end
- alias_method :minus_without_duration, :-
- alias_method :-, :minus_with_duration
-
# Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
# any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
def advance(options)
@@ -129,15 +110,4 @@ class Date
options.fetch(:day, day)
)
end
-
- # Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
- def compare_with_coercion(other)
- if other.is_a?(Time)
- self.to_datetime <=> other
- else
- compare_without_coercion(other)
- end
- end
- alias_method :compare_without_coercion, :<=>
- alias_method :<=>, :compare_with_coercion
end
diff --git a/activesupport/lib/active_support/core_ext/date/operators.rb b/activesupport/lib/active_support/core_ext/date/operators.rb
new file mode 100644
index 0000000000..decf099624
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/date/operators.rb
@@ -0,0 +1,16 @@
+require 'active_support/core_ext/date_and_time/with_duration'
+
+module ActiveSupport
+ module DateOperators # :nodoc:
+ include DateAndTime::WithDuration
+
+ # Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
+ def <=>(other)
+ if other.is_a?(Time)
+ self.to_datetime <=> other
+ else
+ super
+ end
+ end
+ end
+end