Module

ActiveSupport::CoreExtensions::Time::Calculations

Inheritance

Enables the use of time calculations within Time itself

Classes & Modules

Constants

Name   Description
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

Methods

Instance

Visibility Signature
public advance (options)
public ago (seconds)
public at_beginning_of_day ()
public at_beginning_of_month ()
public at_beginning_of_quarter ()
public at_beginning_of_week ()
public at_beginning_of_year ()
public at_end_of_month ()
public at_end_of_quarter ()
public at_end_of_week ()
public at_end_of_year ()
public at_midnight ()
public beginning_of_day ()
public beginning_of_month ()
public beginning_of_quarter ()
public beginning_of_week ()
public beginning_of_year ()
public change (options)
public compare_with_coercion (other)
public end_of_day ()
public end_of_month ()
public end_of_quarter ()
public end_of_week ()
public end_of_year ()
public future? ()
public in (seconds)
public last_month ()
public last_year ()
public midnight ()
public minus_with_coercion (other)
public monday ()
public months_ago (months)
public months_since (months)
public next_month ()
public next_week (day = :monday)
public next_year ()
public past? ()
public seconds_since_midnight ()
public since (seconds)
public today? ()
public tomorrow ()
public years_ago (years)
public years_since (years)
public yesterday ()

Instance Method Detail

advance(options)

Uses Date to provide precise Time calculations for years, months, and days. The options parameter takes a hash with any of these keys: :years, :months, :weeks, :days, :hours, :minutes, :seconds.

ago(seconds)

Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension

at_beginning_of_day()

Alias for beginning_of_day

at_beginning_of_month()

Alias for beginning_of_month

at_beginning_of_quarter()

at_beginning_of_week()

Alias for beginning_of_week

at_beginning_of_year()

Alias for beginning_of_year

at_end_of_month()

Alias for end_of_month

at_end_of_quarter()

Alias for end_of_quarter

at_end_of_week()

Alias for end_of_week

at_end_of_year()

Alias for end_of_year

at_midnight()

Alias for beginning_of_day

beginning_of_day()

Returns a new Time representing the start of the day (0:00)

beginning_of_month()

Returns a new Time representing the start of the month (1st of the month, 0:00)

beginning_of_quarter()

Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00)

beginning_of_week()

Returns a new Time representing the "start" of this week (Monday, 0:00)

beginning_of_year()

Returns a new Time representing the start of the year (1st of january, 0:00)

change(options)

Returns a new Time where one or more of the elements have been changed according to the options parameter. The time options (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed, then minute, sec, and usec is set to 0. If the hour and minute is passed, then sec and usec is set to 0.

compare_with_coercion(other)

Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances can be chronologically compared with a Time

end_of_day()

Returns a new Time representing the end of the day (23:59:59)

end_of_month()

Returns a new Time representing the end of the month (last day of the month, 0:00)

end_of_quarter()

Returns a new Time representing the end of the quarter (last day of march, june, september, december, 23:59:59)

end_of_week()

Returns a new Time representing the end of this week (Sunday, 23:59:59)

end_of_year()

Returns a new Time representing the end of the year (31st of december, 23:59:59)

future?()

Tells whether the Time object‘s time lies in the future

in(seconds)

Alias for since

last_month()

Short-hand for months_ago(1)

last_year()

Short-hand for years_ago(1)

midnight()

Alias for beginning_of_day

minus_with_coercion(other)

Time#- can also be used to determine the number of seconds between two Time instances. We‘re layering on additional behavior so that ActiveSupport::TimeWithZone instances are coerced into values that Time#- will recognize

monday()

Alias for beginning_of_week

months_ago(months)

Returns a new Time representing the time a number of specified months ago

months_since(months)

Returns a new Time representing the time a number of specified months in the future

next_month()

Short-hand for months_since(1)

next_week(day = :monday)

Returns a new Time representing the start of the given day in next week (default is Monday).

next_year()

Short-hand for years_since(1)

past?()

Tells whether the Time object‘s time lies in the past

seconds_since_midnight()

since(seconds)

Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around the Numeric extension.

today?()

Tells whether the Time object‘s time is today

tomorrow()

Convenience method which returns a new Time representing the time 1 day since the instance time

years_ago(years)

Returns a new Time representing the time a number of specified years ago

years_since(years)

Returns a new Time representing the time a number of specified years in the future

yesterday()

Convenience method which returns a new Time representing the time 1 day ago