aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/date/conversions.rb12
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb4
3 files changed, 14 insertions, 4 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index cc79c9d7c4..3ddfc19643 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 bae20c66db..4b9388dacd 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 ActiveSupport #:nodoc:
: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 @@ module ActiveSupport #:nodoc:
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 71c2ed1f3a..56161954a0 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -10,6 +10,10 @@ class DateExtCalculationsTest < Test::Unit::TestCase
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