instance method
parse
Ruby on Rails edge
Signature
parse(str, now = now())
Method for creating new ActiveSupport::TimeWithZone instance in time zone of self from parsed string.
Time.zone = 'Hawaii' # => "Hawaii"
Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
If upper components are missing from the string, they are supplied from TimeZone#now:
Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00
Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
However, if the date component is not provided, but any other upper components are supplied, then the day of the month defaults to 1:
Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
Strings with no recognizable date information return nil, while strings with out-of-range components raise ArgumentError:
Time.zone.parse('foobar') # => nil
Time.zone.parse('9000') # => ArgumentError: argument out of range
Set ActiveSupport.raise_on_invalid_time_zone_parse to true to raise ArgumentError in both cases.
Parameters
-
strreq -
nowopt = now()
Source
# File activesupport/lib/active_support/values/time_zone.rb, line 472
def parse(str, now = now())
parts_to_time(Date._parse(str, false), now)
end
Defined in activesupport/lib/active_support/values/time_zone.rb line 472
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::TimeZone