From 9d4d2ef4465e3f3b7576577c942eb958b0092780 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 1 Aug 2026 23:24:52 -0700 Subject: [PATCH] Make Time.rfc3339 require minutes in offset This is required by RFC 3339 section 5.6, which does not allow for an offset without a minute. Fixes #73 --- lib/time.rb | 2 +- test/test_time.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/time.rb b/lib/time.rb index 4d1a027..0dac394 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 ac7a5b6..473803b 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -124,7 +124,11 @@ def subtest_xmlschema_alias(method) 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)/, ''))) - assert_equal(t, Time.__send__(method, s.sub(/:00\z/, ''))) + if method == :rfc3339 + assert_raise(ArgumentError) { Time.rfc3339(s.sub(/:00\z/, '')) } + else + assert_equal(t, Time.__send__(method, s.sub(/:00\z/, ''))) + end # There is no way to generate time string with arbitrary timezone. s = "1996-12-20T00:39:57Z" assert_equal(t, Time.__send__(method, s)) @@ -182,6 +186,7 @@ def subtest_xmlschema(method) [Time.local(2000, 1, 1, 12, 0, 0), "2000-01-01T12:00:00"], [Time.local(2000, 1, 16, 12, 0, 0), "2000-01-16T12:00:00"], [Time.local(2000, 1, 16, 0, 0, 0), "2000-01-16T00:00:00"], + [Time.utc(2000, 1, 16, 0, 0, 0), "2000-01-16T00:00:00+00"], ] local_times.each do |expected, time| if method == :rfc3339