class ActiveSupport::TimeZone

def iso8601(str)

which usually returns +nil+ when given an invalid date string.
If the string is invalid then an +ArgumentError+ will be raised unlike +parse+

Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00
Time.zone = 'Hawaii' # => "Hawaii"

If the time components are missing then they will be set to zero.

Time.zone.iso8601('1999-12-31T14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
Time.zone = 'Hawaii' # => "Hawaii"

of +self+ from an ISO 8601 string.
Method for creating new ActiveSupport::TimeWithZone instance in time zone
def iso8601(str)
  # Historically `Date._iso8601(nil)` returns `{}`, but in the `date` gem versions `3.2.1`, `3.1.2`, `3.0.2`,
  # and `2.0.1`, `Date._iso8601(nil)` raises `TypeError` https://github.com/ruby/date/issues/39
  # Future `date` releases are expected to revert back to the original behavior.
  raise ArgumentError, "invalid date" if str.nil?
  parts = Date._iso8601(str)
  year = parts.fetch(:year)
  if parts.key?(:yday)
    ordinal_date = Date.ordinal(year, parts.fetch(:yday))
    month = ordinal_date.month
    day = ordinal_date.day
  else
    month = parts.fetch(:mon)
    day = parts.fetch(:mday)
  end
  time = Time.new(
    year,
    month,
    day,
    parts.fetch(:hour, 0),
    parts.fetch(:min, 0),
    parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
    parts.fetch(:offset, 0)
  )
  if parts[:offset]
    TimeWithZone.new(time.utc, self)
  else
    TimeWithZone.new(nil, self, time)
  end
rescue Date::Error, KeyError
  raise ArgumentError, "invalid date"
end