diff options
3 files changed, 12 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 48d474dd9a..092f936961 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -1,5 +1,6 @@ require 'date' require 'active_support/inflector' +require 'active_support/core_ext/date/zones' class Date DATE_FORMATS = { @@ -12,7 +13,10 @@ class Date } # Ruby 1.9 has Date#to_time which converts to localtime only. - remove_method :to_time if instance_methods.include?(:to_time) + remove_method :to_time if method_defined?(:to_time) + + # Ruby 1.9 has Date#xmlschema which converts to a string without the time component. + remove_method :xmlschema if method_defined?(:xmlschema) # Convert to a formatted string. See DATE_FORMATS for predefined formats. # @@ -77,7 +81,7 @@ class Date def to_time(form = :local) ::Time.send("#{form}_time", year, month, day) end - + # Converts a Date instance to a DateTime, where the time is set to the beginning of the day # and UTC offset is set to 0. # @@ -88,4 +92,8 @@ class Date def to_datetime ::DateTime.civil(year, month, day, 0, 0, 0, 0) end if RUBY_VERSION < '1.9' + + def xmlschema + to_time_in_current_zone.xmlschema + end end diff --git a/activesupport/lib/active_support/core_ext/date/zones.rb b/activesupport/lib/active_support/core_ext/date/zones.rb index 722f086951..3a83af6be2 100644 --- a/activesupport/lib/active_support/core_ext/date/zones.rb +++ b/activesupport/lib/active_support/core_ext/date/zones.rb @@ -11,11 +11,4 @@ class Date to_time end end - - # Ruby 1.9 has Date#xmlschema which converts to a string without the time component. - remove_method :xmlschema if instance_methods.include?(:xmlschema) - - def xmlschema - to_time_in_current_zone.xmlschema - end end diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 315897b423..2f9588e0f4 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -11,6 +11,8 @@ require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/object/instance_variables' require 'time' require 'active_support/core_ext/time/conversions' +require 'active_support/core_ext/date_time/conversions' +require 'active_support/core_ext/date/conversions' module ActiveSupport class << self |