Skip to content

Time.rfc3339 accepts a UTC offset without a colon #77

Description

@yahonda

Follow-up to #73 / #74: Time.rfc3339 on master (tested at 95ab5fa) accepts a numeric UTC offset written without the colon separator, which Section 5.6 of RFC 3339 does not allow.

Steps to reproduce

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"
  gem "time", github: "ruby/time"
end

require "time"
require "date"

p Time.rfc3339("1999-12-31T19:00:00-0400")
p DateTime.rfc3339("1999-12-31T19:00:00-0400")

Expected behavior

Both calls raise. The ABNF in Section 5.6 (https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) reads:

time-numoffset  = ("+" / "-") time-hour ":" time-minute

The colon between the hour and the minute of a numeric offset is not optional.

Actual behavior

1999-12-31 19:00:00 -0400
repro.rb:12:in 'DateTime.rfc3339': invalid date (Date::Error)

Time.rfc3339 accepts the string; DateTime.rfc3339 rejects it. The colon is optional in the offset group of the pattern:

(Z|[+-]\d\d:?\d\d)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions