diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-02 13:07:02 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-02 13:07:02 +0000 |
commit | 6d688aa20c1075aa37134c2bfa9d7eae75f90437 (patch) | |
tree | 9e999a07d9453164e93327474fc3feacea4012b8 /activesupport/lib/active_support/core_ext/string/conversions.rb | |
parent | 7093c9aaab514398e757cb22a44d134cbab95068 (diff) | |
download | rails-6d688aa20c1075aa37134c2bfa9d7eae75f90437.tar.gz rails-6d688aa20c1075aa37134c2bfa9d7eae75f90437.tar.bz2 rails-6d688aa20c1075aa37134c2bfa9d7eae75f90437.zip |
Added String#to_time and String#to_date for wrapping ParseDate
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@824 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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 |