Module ActiveSupport::CoreExtensions::Date::Calculations
In: lib/active_support/core_ext/date/calculations.rb

Enables the use of time calculations within Date itself

Methods

Classes and Modules

Module ActiveSupport::CoreExtensions::Date::Calculations::ClassMethods

Public Instance methods

Provides precise Date calculations for years, months, and days. The options parameter takes a hash with any of these keys: :years, :months, :weeks, :days.

Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) and then subtracts the specified number of seconds

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

Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)

Returns a new ; DateTime objects will have time set to 0:00DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00)

Returns a new Date/DateTime representing the start of the quarter (1st of january, april, july, october; DateTime objects will have time set to 0:00)

Returns a new Date/DateTime representing the "start" of this week (i.e, Monday; DateTime objects will have time set to 0:00)

Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00)

Returns a new Date where one or more of the elements have been changed according to the options parameter.

Examples:

  Date.new(2007, 5, 12).change(:day => 1)                  # => Date.new(2007, 5, 1)
  Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12)

Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59)

Returns a new Date/DateTime representing the end of the month (last day of the month; DateTime objects will have time set to 0:00)

Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59)

Returns a new Date/DateTime representing the end of this week (Sunday, DateTime objects will have time set to 23:59:59)

Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59)

Tells whether the Date object‘s date lies in the future

in(seconds)

Alias for since

midnight()

Alias for beginning_of_day

monday()

Alias for beginning_of_week

Returns a new Date/DateTime representing the time a number of specified months ago

Returns a new Date/DateTime representing the time a number of specified months in the future

Short-hand for months_since(1)

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

Short-hand for years_since(1)

Tells whether the Date object‘s date lies in the past

Short-hand for months_ago(1)

Short-hand for years_ago(1)

Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) and then adds the specified number of seconds

Tells whether the Date object‘s date is today

Convenience method which returns a new Date/DateTime representing the time 1 day since the instance time

Returns a new Date/DateTime representing the time a number of specified years ago

Returns a new Date/DateTime representing the time a number of specified years in the future

Convenience method which returns a new Date/DateTime representing the time 1 day ago

[Validate]