Froze rails gems
[depot.git] / vendor / rails / activesupport / lib / active_support / core_ext / string / conversions.rb
1 require 'date'
2
3 module ActiveSupport #:nodoc:
4 module CoreExtensions #:nodoc:
5 module String #:nodoc:
6 # Converting strings to other objects
7 module Conversions
8 # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
9 def ord
10 self[0]
11 end if RUBY_VERSION < '1.9'
12
13 # Form can be either :utc (default) or :local.
14 def to_time(form = :utc)
15 ::Time.send("#{form}_time", *::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 })
16 end
17
18 def to_date
19 ::Date.new(*::Date._parse(self, false).values_at(:year, :mon, :mday))
20 end
21
22 def to_datetime
23 ::DateTime.civil(*::Date._parse(self, false).values_at(:year, :mon, :mday, :hour, :min, :sec).map { |arg| arg || 0 })
24 end
25 end
26 end
27 end
28 end