Module | ActiveSupport::CoreExtensions::Time::Calculations
In: | lib/active_support/core_ext/time/calculations.rb

Enables the use of time calculations within Time itself

### Methods

advance ago at_beginning_of_day at_beginning_of_month at_beginning_of_quarter at_beginning_of_week at_beginning_of_year at_end_of_month at_end_of_quarter at_end_of_week at_end_of_year at_midnight beginning_of_day beginning_of_month beginning_of_quarter beginning_of_week beginning_of_year change compare_with_coercion end_of_day end_of_month end_of_quarter end_of_week end_of_year future? in last_month last_year midnight minus_with_coercion monday months_ago months_since next_month next_week next_year past? seconds_since_midnight since today? tomorrow years_ago years_since yesterday

### Classes and Modules

Module ActiveSupport::CoreExtensions::Time::Calculations::ClassMethods

### Constants

COMMON_YEAR_DAYS_IN_MONTH | = | [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

### Public Instance methods

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()

Alias for 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()

Seconds since midnight: Time.now.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

[Validate]