ActiveSupport::CoreExtensions::Date::Calculations


Files

Description

Enables the use of time calculations within Time itself

Methods

Classes and Modules

Public Instance methods

advance (options)

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

ago (seconds)

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

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)

Alias

midnight

Alias

at_midnight

Alias

at_beginning_of_day

beginning_of_month ()

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)

Alias

at_beginning_of_month

beginning_of_quarter ()

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)

Alias

at_beginning_of_quarter

beginning_of_week ()

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

Alias

monday

Alias

at_beginning_of_week

beginning_of_year ()

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

Alias

at_beginning_of_year

change (options)

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)

end_of_day ()

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

end_of_month ()

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)

Alias

at_end_of_month

end_of_quarter ()

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)

Alias

at_end_of_quarter

end_of_week ()

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

Alias

at_end_of_week

end_of_year ()

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

Alias

at_end_of_year

future? ()

Tells whether the Date object‘s date 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

monday ()

Alias for beginning_of_week

months_ago (months)

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

months_since (months)

Returns a new Date/DateTime 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 Date/DateTime 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 Date object‘s date lies in the past

since (seconds)

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

Alias

in

today? ()

Tells whether the Date object‘s date is today

tomorrow ()

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

years_ago (years)

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

years_since (years)

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

yesterday ()

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