~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/activesupport/lib/active_support/core_ext/string/conversions.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
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