Ticket #7164: documentation_for_time_conversions.with_alias.r8258.diff
| File documentation_for_time_conversions.with_alias.r8258.diff, 3.1 kB (added by chuyeow, 11 months ago) |
|---|
-
activesupport/lib/active_support/core_ext/time/conversions.rb
old new 19 19 end 20 20 end 21 21 22 # Convert to a formatted string - see DATE_FORMATS for predefined formats. 23 # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 24 # 25 # This method is also aliased as <tt>to_s</tt>. 26 # 27 # ==== Examples: 28 # time = Time.now # => Thu Jan 18 06:10:17 CST 2007 29 # 30 # time.to_formatted_s(:time) # => "Thu Jan 18 06:10:17 CST 2007" 31 # time.to_s(:time) # => "Thu Jan 18 06:10:17 CST 2007" 32 # 33 # time.to_formatted_s(:db) # => "2007-01-18 06:10:17" 34 # time.to_formatted_s(:short) # => "18 Jan 06:10" 35 # time.to_formatted_s(:long) # => "January 18, 2007 06:10" 36 # time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10" 37 # time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600" 22 38 def to_formatted_s(format = :default) 23 39 if formatter = DATE_FORMATS[format] 24 40 if formatter.respond_to?(:call) … … 31 47 end 32 48 end 33 49 34 # Converts self to a Ruby Date object; time portion is discarded 50 # Convert a Time object to a Date, dropping hour, minute, and second precision. 51 # 52 # ==== Examples 53 # my_time = Time.now 54 # # => Mon Nov 12 22:59:51 -0500 2007 55 # 56 # my_time.to_date 57 # #=> Mon, 12 Nov 2007 58 # 59 # your_time = Time.parse("1/13/2009 1:13:03 P.M.") 60 # # => Tue Jan 13 13:13:03 -0500 2009 61 # 62 # your_time.to_date 63 # # => Tue, 13 Jan 2009 35 64 def to_date 36 65 ::Date.new(year, month, day) 37 66 end 38 67 39 # To be able to keep Times, Dates and DateTimes interchangeable on conversions 68 # A method to keep Time, Date and DateTime instances interchangeable on conversions. 69 # In this case, it simply returns +self+. 40 70 def to_time 41 71 self 42 72 end 43 73 44 # converts to a Ruby DateTime instance; preserves utc offset 74 # Converts a Time instance to a Ruby DateTime instance, preserving UTC offset. 75 # 76 # ==== Examples 77 # my_time = Time.now 78 # # => Mon Nov 12 23:04:21 -0500 2007 79 # 80 # my_time.to_datetime 81 # # => Mon, 12 Nov 2007 23:04:21 -0500 82 # 83 # your_time = Time.parse("1/13/2009 1:13:03 P.M.") 84 # # => Tue Jan 13 13:13:03 -0500 2009 85 # 86 # your_time.to_datetime 87 # # => Tue, 13 Jan 2009 13:13:03 -0500 45 88 def to_datetime 46 89 ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) 47 90 end