Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tag: v3.0.0.beta1
Fetching contributors…

Cannot retrieve contributors at this time

27 lines (22 sloc) 0.753 kB
require 'date'
require 'active_support/core_ext/time/calculations'
class String
# 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
def ord
self[0]
end unless method_defined?(:ord)
# Form can be either :utc (default) or :local.
def to_time(form = :utc)
d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction).map { |arg| arg || 0 }
d[6] *= 1000000
::Time.send("#{form}_time", *d)
end
def to_date
::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday))
end
def to_datetime
d = ::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :sec_fraction).map { |arg| arg || 0 }
d[5] += d.pop
::DateTime.civil(*d)
end
end
Jump to Line
Something went wrong with that request. Please try again.