Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4718

Show
Ignore:
Timestamp:
08/07/06 22:07:33 (2 years ago)
Author:
bitsweat
Message:

DateTime#to_time gives hour/minute/second resolution. Closes #5747.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r4692 r4718  
    11*SVN* 
     2 
     3* DateTime#to_time gives hour/minute/second resolution.  #5747 [jon.evans@pobox.com] 
    24 
    35* 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] 
  • trunk/activesupport/lib/active_support/core_ext/date/conversions.rb

    r4653 r4718  
    88          :long  => "%B %e, %Y" 
    99        } 
    10          
     10 
    1111        def self.included(klass) #:nodoc: 
    1212          klass.send(:alias_method, :to_default_s, :to_s) 
    1313          klass.send(:alias_method, :to_s, :to_formatted_s) 
    1414        end 
    15          
     15 
    1616        def to_formatted_s(format = :default) 
    17           DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s    
     17          DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s 
    1818        end 
    1919 
     
    2424 
    2525        def to_time(form = :local) 
    26           ::Time.send(form, year, month, day) 
     26          if respond_to?(:hour) 
     27            ::Time.send(form, year, month, day, hour, min, sec) 
     28          else 
     29            ::Time.send(form, year, month, day) 
     30          end 
    2731        end 
    2832 
  • trunk/activesupport/test/core_ext/date_ext_test.rb

    r4595 r4718  
    1111  end 
    1212 
     13  def test_to_time_on_datetime 
     14    assert_equal Time.local(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12).to_time 
     15  end 
     16 
    1317  def test_to_date 
    1418    assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date