2007-01-22 14:43:50 +01:00
|
|
|
require 'parsedate'
|
|
|
|
|
|
|
|
module ActiveSupport #:nodoc:
|
|
|
|
module CoreExtensions #:nodoc:
|
|
|
|
module String #:nodoc:
|
|
|
|
# Converting strings to other objects
|
|
|
|
module Conversions
|
2007-12-21 08:48:59 +01:00
|
|
|
# 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
|
|
|
|
def ord
|
|
|
|
self[0]
|
|
|
|
end if RUBY_VERSION < '1.9'
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
# Form can be either :utc (default) or :local.
|
|
|
|
def to_time(form = :utc)
|
2007-12-21 08:48:59 +01:00
|
|
|
::Time.send("#{form}_time", *ParseDate.parsedate(self)[0..5].map {|arg| arg || 0})
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_date
|
|
|
|
::Date.new(*ParseDate.parsedate(self)[0..2])
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
|
|
|
|
def to_datetime
|
|
|
|
::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0)
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-12-21 08:48:59 +01:00
|
|
|
end
|