diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 40e73ae77f..8f4ec5cb49 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,7 @@ +* Add Time#to_s(:iso8601) for easy conversion of times to the iso8601 format for easy Javascript date parsing. + + *DHH* + * Improve `ActiveSupport::Cache::MemoryStore` cache size calculation. The memory used by a key/entry pair is calculated via `#cached_size`: diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index 48654eb1cc..a87455dedb 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -16,7 +16,8 @@ class Time :rfc822 => lambda { |time| offset_format = time.formatted_offset(false) time.strftime("%a, %d %b %Y %H:%M:%S #{offset_format}") - } + }, + :iso8601 => "%Y-%m-%dT%H:%M:%SZ" } # Converts to a formatted string. See DATE_FORMATS for builtin formats. diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 8741f033b5..c9e9d5cbc4 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -503,6 +503,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase assert_equal "20050221174430123456789", time.to_s(:nsec) assert_equal "February 21, 2005 17:44", time.to_s(:long) assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal) + assert_equal "2009-02-05T14:30:05Z", Time.local(2009, 2, 5, 14, 30, 5).to_s(:iso8601) with_env_tz "UTC" do assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822) end