Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,10 @@ def rfc2822(date)
:\s*(\d{2})
(?:\s*:\s*(\d\d))?\s+
([+-]\d{4}|
UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Z])/ix =~ date
UTC|UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[A-IK-Z])\b/ix =~ date
# Since RFC 2822 permit comments, the regexp has no right anchor.
# The zone must still end there, so that "CET" is not read as the
# military zone "C".
day = $1.to_i
mon = MonthValue[$2.upcase]
year = $3.to_i
Expand Down
18 changes: 18 additions & 0 deletions test/test_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def test_rfc2822
assert_equal(true, t.utc?)
end

def test_rfc2822_zone_end
t = Time.rfc2822("Sat, 01 Jan 2000 12:00:00 UTC")
assert_equal(Time.utc(2000, 1, 1, 12, 0, 0), t)
assert_equal(true, t.utc?)
t = Time.rfc2822("Sat, 01 Jan 2000 12:00:00 GMT(comment)")
assert_equal(Time.utc(2000, 1, 1, 12, 0, 0), t)
t = Time.rfc2822("Sat, 01 Jan 2000 12:00:00 Z")
assert_equal(Time.utc(2000, 1, 1, 12, 0, 0), t)

# A longer zone name is not a military zone with extra letters.
%w[CET CEST HST IST BST MSK EET UTX GMTX ESTX].each do |zone|
assert_raise(ArgumentError, zone) {
Time.rfc2822("Sat, 01 Jan 2000 12:00:00 #{zone}")
}
end
assert_raise(ArgumentError) { Time.rfc2822("Sat, 01 Jan 2000 12:00:00 +09001") }
end

def test_rfc2822_nonlinear
pre = ->(n) {"0 Feb 00 00 :00" + " " * n}
assert_linear_performance([100, 500, 5000, 50_000], pre: pre) do |s|
Expand Down