diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-29 12:28:19 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-29 12:31:20 +0100 |
commit | 88c0ef4d4fc86faefeec5bfff87ad882f62468d8 (patch) | |
tree | 395cf236c5bb23795dcffb613cdc7721b3da1554 /activesupport/lib/active_support/core_ext/time/conversions.rb | |
parent | cde979c38832b99d8c85b5f44f7357931ade1ee0 (diff) | |
download | rails-88c0ef4d4fc86faefeec5bfff87ad882f62468d8.tar.gz rails-88c0ef4d4fc86faefeec5bfff87ad882f62468d8.tar.bz2 rails-88c0ef4d4fc86faefeec5bfff87ad882f62468d8.zip |
Fix handling of offsets with Time#to_s(:iso8601)
Use a lambda to ensure that the generated string respects the offset of
the time value. Also add DateTime#to_s(:iso8601) and Date#to_s(:iso8601)
for completeness.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/conversions.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index a87455dedb..9fd26156c7 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -17,7 +17,7 @@ class 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" + :iso8601 => lambda { |time| time.iso8601 } } # Converts to a formatted string. See DATE_FORMATS for builtin formats. @@ -35,6 +35,7 @@ class Time # time.to_formatted_s(:long) # => "January 18, 2007 06:10" # time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10" # time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600" + # time.to_formatted_s(:iso8601) # => "2007-01-18T06:10:17-06:00" # # == Adding your own time formats to +to_formatted_s+ # You can add your own formats to the Time::DATE_FORMATS hash. |