From a536458471509a5ea37096d16704ffb98ad74c69 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 5 Aug 2026 19:24:52 -0700 Subject: [PATCH] Require colon in timezone offset for Time.rfc3339 Fixes #77 --- lib/time.rb | 2 +- test/test_time.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/time.rb b/lib/time.rb index cb9c304..95f8a30 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -660,7 +660,7 @@ def rfc3339(time) [T\s] (\d\d):(\d\d):(\d\d) (\.\d+)? - (Z|[+-]\d\d:?\d\d) + (Z|[+-]\d\d:\d\d) \s*\z/ix _xmlschema(pattern, time) end diff --git a/test/test_time.rb b/test/test_time.rb index 2bdb35d..53ac856 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -123,10 +123,11 @@ def subtest_xmlschema_alias(method) t = Time.utc(1996, 12, 20, 0, 39, 57) s = "1996-12-19T16:39:57-08:00" assert_equal(t, Time.__send__(method, s)) - assert_equal(t, Time.__send__(method, s.sub(/:(?=00\z)/, ''))) if method == :rfc3339 + assert_raise(ArgumentError) { Time.rfc3339(s.sub(/:(?=00\z)/, '')) } assert_raise(ArgumentError) { Time.rfc3339(s.sub(/:00\z/, '')) } else + assert_equal(t, Time.__send__(method, s.sub(/:(?=00\z)/, ''))) assert_equal(t, Time.__send__(method, s.sub(/:00\z/, ''))) end # There is no way to generate time string with arbitrary timezone.