diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 19 |
2 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index 6d554b483c..3056f74744 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -1,5 +1,7 @@ require File.dirname(__FILE__) + '/string/inflections' +require File.dirname(__FILE__) + '/string/conversions' class String #:nodoc: include ActiveSupport::CoreExtensions::String::Inflections + include ActiveSupport::CoreExtensions::String::Conversions end diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb new file mode 100644 index 0000000000..cfb767d1f9 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -0,0 +1,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
\ No newline at end of file |