class method self.rfc3339

Ruby on Rails edge

Since v5.1.7

Available in: v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

self.rfc3339(str)

Creates a Time instance from an RFC 3339 string.

Time.rfc3339('1999-12-31T14:00:00-10:00') # => 2000-01-01 00:00:00 -1000

If the time or offset components are missing then an ArgumentError will be raised.

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

Strings with the “Z” UTC designator return a UTC time, matching Ruby’s Time.rfc3339.

Time.rfc3339('1999-12-31T14:00:00Z').utc? # => true

Parameters

str req
Source
# File activesupport/lib/active_support/core_ext/time/calculations.rb, line 82
      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)
        )

        # "Z" denotes UTC, which the integer offset alone cannot represent.
        parts[:zone].casecmp?("Z") ? time.utc : time
      end

Defined in activesupport/lib/active_support/core_ext/time/calculations.rb line 82 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Time

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close