1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add Time#to_s(:iso8601) for easy conversion of times to the iso8601 format for easy Javascript date parsing

This commit is contained in:
David Heinemeier Hansson 2013-07-28 16:34:43 -05:00
parent 586173204c
commit b67a80de9b
3 changed files with 7 additions and 1 deletions

View file

@ -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`:

View file

@ -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.

View file

@ -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