Support rfc2822 format for Time#to_fs & Date#to_fs (#52337)
This commit is contained in:
parent
c01a846658
commit
26575aa19c
@ -1,3 +1,7 @@
|
||||
* Support rfc2822 format for Time#to_fs & Date#to_fs.
|
||||
|
||||
*Akshay Birajdar*
|
||||
|
||||
* Optimize load time for `Railtie#initialize_i18n`. Filter `I18n.load_path`s passed to the file watcher to only those
|
||||
under `Rails.root`. Previously the watcher would grab all available locales, including those in gems
|
||||
which do not require a watcher because they won't change.
|
||||
|
@ -17,6 +17,7 @@ class Date
|
||||
date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007"
|
||||
},
|
||||
rfc822: "%d %b %Y",
|
||||
rfc2822: "%d %b %Y",
|
||||
iso8601: lambda { |date| date.iso8601 }
|
||||
}
|
||||
|
||||
@ -34,6 +35,7 @@ class Date
|
||||
# date.to_fs(:long) # => "November 10, 2007"
|
||||
# date.to_fs(:long_ordinal) # => "November 10th, 2007"
|
||||
# date.to_fs(:rfc822) # => "10 Nov 2007"
|
||||
# date.to_fs(:rfc2822) # => "10 Nov 2007"
|
||||
# date.to_fs(:iso8601) # => "2007-11-10"
|
||||
#
|
||||
# == Adding your own date formats to to_fs
|
||||
|
@ -22,6 +22,7 @@ class Time
|
||||
offset_format = time.formatted_offset(false)
|
||||
time.strftime("%a, %d %b %Y %H:%M:%S #{offset_format}")
|
||||
},
|
||||
rfc2822: lambda { |time| time.rfc2822 },
|
||||
iso8601: lambda { |time| time.iso8601 }
|
||||
}
|
||||
|
||||
@ -40,6 +41,7 @@ class Time
|
||||
# time.to_fs(:long) # => "January 18, 2007 06:10"
|
||||
# time.to_fs(:long_ordinal) # => "January 18th, 2007 06:10"
|
||||
# time.to_fs(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
|
||||
# time.to_fs(:rfc2822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
|
||||
# time.to_fs(:iso8601) # => "2007-01-18T06:10:17-06:00"
|
||||
#
|
||||
# == Adding your own time formats to +to_fs+
|
||||
|
@ -29,6 +29,7 @@ def test_to_fs
|
||||
assert_equal "2005-02-21", date.to_fs(:db)
|
||||
assert_equal "2005-02-21", date.to_fs(:inspect)
|
||||
assert_equal "21 Feb 2005", date.to_fs(:rfc822)
|
||||
assert_equal "21 Feb 2005", date.to_fs(:rfc2822)
|
||||
assert_equal "2005-02-21", date.to_fs(:iso8601)
|
||||
assert_equal date.to_s, date.to_fs(:doesnt_exist)
|
||||
assert_equal "21 Feb", date.to_formatted_s(:short)
|
||||
|
@ -21,6 +21,7 @@ def test_to_fs
|
||||
assert_equal "21 Feb 14:30", datetime.to_fs(:short)
|
||||
assert_equal "February 21, 2005 14:30", datetime.to_fs(:long)
|
||||
assert_equal "Mon, 21 Feb 2005 14:30:00 +0000", datetime.to_fs(:rfc822)
|
||||
assert_equal "Mon, 21 Feb 2005 14:30:00 +0000", datetime.to_fs(:rfc2822)
|
||||
assert_equal "February 21st, 2005 14:30", datetime.to_fs(:long_ordinal)
|
||||
assert_match(/^2005-02-21T14:30:00(Z|\+00:00)$/, datetime.to_fs)
|
||||
assert_match(/^2005-02-21T14:30:00(Z|\+00:00)$/, datetime.to_fs(:not_existent))
|
||||
|
@ -832,11 +832,14 @@ def test_to_fs
|
||||
assert_equal "February 21st, 2005 17:44", time.to_fs(:long_ordinal)
|
||||
with_env_tz "UTC" do
|
||||
assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_fs(:rfc822)
|
||||
assert_equal "Mon, 21 Feb 2005 17:44:30 -0000", time.to_fs(:rfc2822)
|
||||
assert_equal "2005-02-21 17:44:30.123456789 +0000", time.to_fs(:inspect)
|
||||
end
|
||||
with_env_tz "US/Central" do
|
||||
assert_equal "Thu, 05 Feb 2009 14:30:05 -0600", Time.local(2009, 2, 5, 14, 30, 5).to_fs(:rfc822)
|
||||
assert_equal "Mon, 09 Jun 2008 04:05:01 -0500", Time.local(2008, 6, 9, 4, 5, 1).to_fs(:rfc822)
|
||||
assert_equal "Thu, 05 Feb 2009 14:30:05 -0600", Time.local(2009, 2, 5, 14, 30, 5).to_fs(:rfc2822)
|
||||
assert_equal "Mon, 09 Jun 2008 04:05:01 -0500", Time.local(2008, 6, 9, 4, 5, 1).to_fs(:rfc2822)
|
||||
assert_equal "2009-02-05T14:30:05-06:00", Time.local(2009, 2, 5, 14, 30, 5).to_fs(:iso8601)
|
||||
assert_equal "2008-06-09T04:05:01-05:00", Time.local(2008, 6, 9, 4, 5, 1).to_fs(:iso8601)
|
||||
assert_equal "2009-02-05T14:30:05Z", Time.utc(2009, 2, 5, 14, 30, 5).to_fs(:iso8601)
|
||||
|
Loading…
Reference in New Issue
Block a user