Prev | Current Page 95 | Next

Brad Ediger

"Advanced Rails"

The :default
format is used if no format is specified.
??? Time#to_s(format) formats a date and time in one of several formats (Table 2-2). The
:default format is used if no format is specified.
Table 2-1. Date formats
Format Example
:default 2006-12-28
:short 28 Dec
:long December 28, 2006
Date and Time
64 | Chapter 2: ActiveSupport and RailTies
Conversions from Numeric core_ext/numeric/time.rb
ActiveSupport adds support methods to the Numeric class to support calculations on dates
and times. Numbers can be added to and subtracted from Time objects; the numbers are
treated as seconds. ActiveSupport??™s conversion methods convert numbers to seconds. Both
singular and plural time units are supported.
1 == 1.second
60.seconds == 1.minute
60.minutes == 1.hour
24.hours == 1.day
7.days == 1.week
2.weeks == 1.fortnight
30.days == 1.month
365.25.days == 1.year
Time.now # => Thu Dec 28 13:30:39 CST 2006
Time.now - 3.days # => Mon Dec 25 13:30:39 CST 2006
3.days.ago # => Mon Dec 25 13:30:39 CST 2006
5.hours.from_now # => Thu Dec 28 18:30:39 CST 2006
Time calculations core_ext/time/calculations.rb
??? Time.days_in_month(month, year) returns the number of days in the provided month.
Year is optional, but if provided, the function will take leap years into account.
Time.days_in_month(2) # => 28
Time.days_in_month(2, 2003) # => 28
Time.days_in_month(2, 2004) # => 29
??? Time#change(options) resets one or more components of the time.


Pages:
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107