From b7d2dae6dcf00b38a1dba8687d6b70d863da915e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 30 May 2007 06:24:32 +0000 Subject: 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 --- .../lib/active_support/core_ext/date/conversions.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/date/conversions.rb') diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 01dd8461e4..25745b0f8b 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -7,7 +7,8 @@ module ActiveSupport #:nodoc: :short => "%e %b", :long => "%B %e, %Y", :db => "%Y-%m-%d", - :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") } # => "April 25th, 2007" + :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }, # => "April 25th, 2007" + :rfc822 => "%e %b %Y" } def self.included(klass) #:nodoc: @@ -27,17 +28,20 @@ module ActiveSupport #:nodoc: end end - # To be able to keep Dates and Times interchangeable on conversions + # To be able to keep Times, Dates and DateTimes interchangeable on conversions def to_date self end + # Converts self to a Ruby Time object; time is set to beginning of day + # Timezone can either be :local or :utc (default :local) def to_time(form = :local) - if respond_to?(:hour) - ::Time.send(form, year, month, day, hour, min, sec) - else - ::Time.send(form, year, month, day) - end + ::Time.send("#{form}_time", year, month, day) + end + + # Converts self to a Ruby DateTime object; time is set to beginning of day + def to_datetime + ::DateTime.civil(year, month, day, 0, 0, 0, 0, 0) end def xmlschema -- cgit v1.2.3