diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index cc79c9d7c4280928f8fd216c78d0e2d842227df2..3ddfc19643c8d7df4482c15a335b2969ee00431d 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* DateTime#to_time gives hour/minute/second resolution. #5747 [jon.evans@pobox.com] + * attr_internal to support namespacing and deprecation. Like attr_* except backed by internally-named instance variable. Set attr_internal_naming_format to change the format from the default '@_%s'. [Jeremy Kemper] # def foo() @foo__rofl end # def foo=(v) @foo__rofl = v end diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index bae20c66db8bb8886ccf078588d40b94c2b9c4be..4b9388dacd6ea020f1672f7d7b7b298d6d2b0c48 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -7,14 +7,14 @@ module Conversions :short => "%e %b", :long => "%B %e, %Y" } - + def self.included(klass) #:nodoc: klass.send(:alias_method, :to_default_s, :to_s) klass.send(:alias_method, :to_s, :to_formatted_s) end - + def to_formatted_s(format = :default) - DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s + DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s end # To be able to keep Dates and Times interchangeable on conversions @@ -23,7 +23,11 @@ def to_date end def to_time(form = :local) - ::Time.send(form, year, month, day) + if respond_to?(:hour) + ::Time.send(form, year, month, day, hour, min, sec) + else + ::Time.send(form, year, month, day) + end end def xmlschema diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 71c2ed1f3a524cd9fe9ad84dcadacb8460e7930a..56161954a067a8e7a13a528a04df9a499d32aec1 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -10,6 +10,10 @@ def test_to_time assert_equal Time.local(2005, 2, 21), Date.new(2005, 2, 21).to_time end + def test_to_time_on_datetime + assert_equal Time.local(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12).to_time + end + def test_to_date assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date end