instance method rfc3339

Ruby on Rails 7.0.10

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

rfc3339(str)

Method for creating new ActiveSupport::TimeWithZone instance in time zone of self from an RFC 3339 string.

Time.zone = 'Hawaii'                     # => "Hawaii"
Time.zone.rfc3339('2000-01-01T00:00:00Z') # => Fri, 31 Dec 1999 14:00:00 HST -10:00

If the time or zone components are missing then an ArgumentError will be raised. This is much stricter than either parse or iso8601 which allow for missing components.

Time.zone = 'Hawaii'            # => "Hawaii"
Time.zone.rfc3339('1999-12-31') # => ArgumentError: invalid date

Parameters

str req
Source
# File activesupport/lib/active_support/values/time_zone.rb, line 460
    def rfc3339(str)
      parts = Date._rfc3339(str)

      raise ArgumentError, "invalid date" if parts.empty?

      time = Time.new(
        parts.fetch(:year),
        parts.fetch(:mon),
        parts.fetch(:mday),
        parts.fetch(:hour),
        parts.fetch(:min),
        parts.fetch(:sec) + parts.fetch(:sec_fraction, 0),
        parts.fetch(:offset)
      )

      TimeWithZone.new(time.utc, self)
    end

Defined in activesupport/lib/active_support/values/time_zone.rb line 460 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::TimeZone

Type at least 2 characters to search.

↑↓ navigate · open · esc close