aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-04 17:49:43 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-04 17:49:43 +0000
commit1312259294e859646d5c1a4d3000f2cd160fae94 (patch)
treefbfdc67cb99f8ac96d3384c49bb4d94b5a92b1f9 /activesupport/lib
parent3cfb894bac2f25f2160189e4909ae7756927d8ad (diff)
downloadrails-1312259294e859646d5c1a4d3000f2cd160fae94.tar.gz
rails-1312259294e859646d5c1a4d3000f2cd160fae94.tar.bz2
rails-1312259294e859646d5c1a4d3000f2cd160fae94.zip
Readable Date and DateTime#inspect. Closes #8570.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6933 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/date/conversions.rb7
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb7
2 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb
index 25745b0f8b..6e864aee5e 100644
--- a/activesupport/lib/active_support/core_ext/date/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date/conversions.rb
@@ -14,6 +14,8 @@ module ActiveSupport #:nodoc:
def self.included(klass) #:nodoc:
klass.send(:alias_method, :to_default_s, :to_s)
klass.send(:alias_method, :to_s, :to_formatted_s)
+ klass.send(:alias_method, :default_inspect, :inspect)
+ klass.send(:alias_method, :inspect, :readable_inspect)
end
def to_formatted_s(format = :default)
@@ -27,6 +29,11 @@ module ActiveSupport #:nodoc:
to_default_s
end
end
+
+ # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
+ def readable_inspect
+ strftime("%a, %d %b %Y")
+ end
# To be able to keep Times, Dates and DateTimes interchangeable on conversions
def to_date
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 1b78a72eea..ce0bfd8e0a 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -6,6 +6,8 @@ module ActiveSupport #:nodoc:
def self.included(klass)
klass.send(:alias_method, :to_datetime_default_s, :to_s)
klass.send(:alias_method, :to_s, :to_formatted_s)
+ klass.send(:alias_method, :default_inspect, :inspect)
+ klass.send(:alias_method, :inspect, :readable_inspect)
end
def to_formatted_s(format = :default)
@@ -19,6 +21,11 @@ module ActiveSupport #:nodoc:
to_datetime_default_s
end
end
+
+ # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000"
+ def readable_inspect
+ to_s(:rfc822)
+ end
# Converts self to a Ruby Date object; time portion is discarded
def to_date