diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-30 06:24:32 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-30 06:24:32 +0000 |
commit | b7d2dae6dcf00b38a1dba8687d6b70d863da915e (patch) | |
tree | 7bbc63855cf78b39a60abc1fd1f26b970cc56890 /activesupport/lib/active_support/core_ext/date_time/conversions.rb | |
parent | 6503da69910beb382b18127c51cd318631245607 (diff) | |
download | rails-b7d2dae6dcf00b38a1dba8687d6b70d863da915e.tar.gz rails-b7d2dae6dcf00b38a1dba8687d6b70d863da915e.tar.bz2 rails-b7d2dae6dcf00b38a1dba8687d6b70d863da915e.zip |
DateTime#to_time converts to Time unless out of range. Date#to_datetime and Date#to_s(:rfc822). Closes #8512.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6902 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/conversions.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index 0b66593499..1b78a72eea 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -20,11 +20,19 @@ module ActiveSupport #:nodoc: end end + # Converts self to a Ruby Date object; time portion is discarded def to_date ::Date.new(year, month, day) end - # To be able to keep Times and DateTimes interchangeable on conversions + # Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class + # If self.offset is 0, then will attempt to cast as a utc time; otherwise will attempt to cast in local time zone + def to_time + method = if self.offset == 0 then 'utc' else 'local' end + ::Time.send(method, year, month, day, hour, min, sec) rescue self + end + + # To be able to keep Times, Dates and DateTimes interchangeable on conversions def to_datetime self end |