Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

to_date, to_time, and to_datetime Time methods present in ruby 1.9 #4432

Merged
merged 1 commit into from

3 participants

@lest

No description provided.

@spastorino spastorino merged commit 31472ba into from
@mitio

@lest could you please help me understand where does the Ruby core library define, for example, Time#to_date?

I checked core-1.9.2, core-1.9.3 and core-2.0 Time docs and I don't see #to_date defined there. I also tested in 1.9.3-p0 for Time#to_date, but it's not there.

Maybe I'm missing something?

It's implemented in date extension. Here is example https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L9281.
Time#to_date method becomes available when date is required.

I see, thanks for clarifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 0 additions and 28 deletions.
  1. +0 −28 activesupport/lib/active_support/core_ext/time/conversions.rb
View
28 activesupport/lib/active_support/core_ext/time/conversions.rb
@@ -53,32 +53,4 @@ def to_formatted_s(format = :default)
def formatted_offset(colon = true, alternate_utc_string = nil)
utc? && alternate_utc_string || ActiveSupport::TimeZone.seconds_to_utc_offset(utc_offset, colon)
end
-
- # Converts a Time object to a Date, dropping hour, minute, and second precision.
- #
- # my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007
- # my_time.to_date # => Mon, 12 Nov 2007
- #
- # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
- # your_time.to_date # => Tue, 13 Jan 2009
- def to_date
- ::Date.new(year, month, day)
- end unless method_defined?(:to_date)
-
- # A method to keep Time, Date and DateTime instances interchangeable on conversions.
- # In this case, it simply returns +self+.
- def to_time
- self
- end unless method_defined?(:to_time)
-
- # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
- #
- # my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007
- # my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500
- #
- # your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
- # your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500
- def to_datetime
- ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400))
- end unless method_defined?(:to_datetime)
end
Something went wrong with that request. Please try again.