aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/conversions.rb
blob: cfb767d1f9fbc93de2b158cf7d63d0ca3986d1a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'parsedate'

module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module String #:nodoc:
      # Converting strings to other objects
      module Conversions
        # Form can be either :utc (default) or :local.
        def to_time(form = :utc)
          ::Time.send(form, *ParseDate.parsedate(self))
        end

        def to_date
          ::Date.new(*ParseDate.parsedate(self)[0..2])
        end
      end
    end
  end
end