instance method
parse
Ruby on Rails 3.2.22.5
Since v2.2.3Signature
parse(str, now=self.now)
Method for creating new ActiveSupport::TimeWithZone instance in time zone of self from parsed string. Example:
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
Parameters
-
strreq -
nowopt = self.now
Source
# File activesupport/lib/active_support/values/time_zone.rb, line 271
def parse(str, now=self.now)
parts = Date._parse(str, false)
return if parts.empty?
time = Time.utc(
parts.fetch(:year, now.year),
parts.fetch(:mon, now.month),
parts.fetch(:mday, now.day),
parts.fetch(:hour, 0),
parts.fetch(:min, 0),
parts.fetch(:sec, 0),
parts.fetch(:sec_fraction, 0) * 1000000
)
if parts[:offset]
TimeWithZone.new(time - parts[:offset], self)
else
TimeWithZone.new(nil, self, time)
end
end
Defined in activesupport/lib/active_support/values/time_zone.rb line 271
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::TimeZone