- A
- B
- D
- E
- F
- L
- M
- N
- O
- P
- S
- T
- W
- Y
Constants
DAYS_INTO_WEEK | = | { sunday: 0, monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6 } |
WEEKEND_DAYS | = | [ 6, 0 ] |
Instance Public methods
after?(date_or_time) Link
Returns true if the date/time falls after date_or_time
.
all_week(start_day = Date.beginning_of_week) Link
Returns a Range
representing the whole week of the current date/time. Week starts on start_day, default is Date.beginning_of_week
or config.beginning_of_week
when set.
before?(date_or_time) Link
Returns true if the date/time falls before date_or_time
.
beginning_of_month() Link
Returns a new date/time at the start of the month.
today = Date.today # => Thu, 18 Jun 2015
today.beginning_of_month # => Mon, 01 Jun 2015
DateTime
objects will have a time set to 0:00.
now = DateTime.current # => Thu, 18 Jun 2015 15:23:13 +0000
now.beginning_of_month # => Mon, 01 Jun 2015 00:00:00 +0000
beginning_of_quarter() Link
Returns a new date/time at the start of the quarter.
today = Date.today # => Fri, 10 Jul 2015
today.beginning_of_quarter # => Wed, 01 Jul 2015
DateTime
objects will have a time set to 0:00.
now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
now.beginning_of_quarter # => Wed, 01 Jul 2015 00:00:00 +0000
beginning_of_week(start_day = Date.beginning_of_week) Link
Returns a new date/time representing the start of this week on the given day. Week is assumed to start on start_day
, default is Date.beginning_of_week
or config.beginning_of_week
when set. DateTime
objects have their time set to 0:00.
beginning_of_year() Link
Returns a new date/time at the beginning of the year.
today = Date.today # => Fri, 10 Jul 2015
today.beginning_of_year # => Thu, 01 Jan 2015
DateTime
objects will have a time set to 0:00.
now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
now.beginning_of_year # => Thu, 01 Jan 2015 00:00:00 +0000
days_ago(days) Link
Returns a new date/time the specified number of days ago.
days_since(days) Link
Returns a new date/time the specified number of days in the future.
days_to_week_start(start_day = Date.beginning_of_week) Link
Returns the number of days to the start of the week on the given day. Week is assumed to start on start_day
, default is Date.beginning_of_week
or config.beginning_of_week
when set.
end_of_month() Link
Returns a new date/time representing the end of the month. DateTime
objects will have a time set to 23:59:59.
end_of_quarter() Link
Returns a new date/time at the end of the quarter.
today = Date.today # => Fri, 10 Jul 2015
today.end_of_quarter # => Wed, 30 Sep 2015
DateTime
objects will have a time set to 23:59:59.
now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000
now.end_of_quarter # => Wed, 30 Sep 2015 23:59:59 +0000
end_of_week(start_day = Date.beginning_of_week) Link
Returns a new date/time representing the end of this week on the given day. Week is assumed to start on start_day
, default is Date.beginning_of_week
or config.beginning_of_week
when set. DateTime
objects have their time set to 23:59:59.
end_of_year() Link
Returns a new date/time representing the end of the year. DateTime
objects will have a time set to 23:59:59.
future?() Link
Returns true if the date/time is in the future.
last_month() Link
Short-hand for months_ago
(1).
monday() Link
Returns Monday of this week assuming that week starts on Monday. DateTime
objects have their time set to 0:00.
months_ago(months) Link
Returns a new date/time the specified number of months ago.
months_since(months) Link
Returns a new date/time the specified number of months in the future.
next_occurring(day_of_week) Link
Returns a new date/time representing the next occurrence of the specified day of week.
today = Date.today # => Thu, 14 Dec 2017
today.next_occurring(:monday) # => Mon, 18 Dec 2017
today.next_occurring(:thursday) # => Thu, 21 Dec 2017
next_quarter() Link
Short-hand for months_since
(3)
next_week(given_day_in_next_week = Date.beginning_of_week, same_time: false) Link
Returns a new date/time representing the given day in the next week.
today = Date.today # => Thu, 07 May 2015
today.next_week # => Mon, 11 May 2015
The given_day_in_next_week
defaults to the beginning of the week which is determined by Date.beginning_of_week
or config.beginning_of_week
when set.
today = Date.today # => Thu, 07 May 2015
today.next_week(:friday) # => Fri, 15 May 2015
DateTime
objects have their time set to 0:00 unless same_time
is true.
now = DateTime.current # => Thu, 07 May 2015 13:31:16 +0000
now.next_week # => Mon, 11 May 2015 00:00:00 +0000
# File activesupport/lib/active_support/core_ext/date_and_time/calculations.rb, line 190 def next_week(given_day_in_next_week = Date.beginning_of_week, same_time: false) result = first_hour(weeks_since(1).beginning_of_week.days_since(days_span(given_day_in_next_week))) same_time ? copy_time_to(result) : result end
next_weekday() Link
Returns a new date/time representing the next weekday.
on_weekday?() Link
Returns true if the date/time does not fall on a Saturday or Sunday.
on_weekend?() Link
Returns true if the date/time falls on a Saturday or Sunday.
past?() Link
Returns true if the date/time is in the past.
prev_occurring(day_of_week) Link
Returns a new date/time representing the previous occurrence of the specified day of week.
today = Date.today # => Thu, 14 Dec 2017
today.prev_occurring(:monday) # => Mon, 11 Dec 2017
today.prev_occurring(:thursday) # => Thu, 07 Dec 2017
prev_week(start_day = Date.beginning_of_week, same_time: false) Link
Returns a new date/time representing the given day in the previous week. Week is assumed to start on start_day
, default is Date.beginning_of_week
or config.beginning_of_week
when set. DateTime
objects have their time set to 0:00 unless same_time
is true.
# File activesupport/lib/active_support/core_ext/date_and_time/calculations.rb, line 213 def prev_week(start_day = Date.beginning_of_week, same_time: false) result = first_hour(weeks_ago(1).beginning_of_week.days_since(days_span(start_day))) same_time ? copy_time_to(result) : result end
prev_weekday() Link
Returns a new date/time representing the previous weekday.
sunday() Link
Returns Sunday of this week assuming that week starts on Monday. DateTime
objects have their time set to 23:59:59.
today?() Link
Returns true if the date/time is today.
tomorrow() Link
Returns a new date/time representing tomorrow.
weeks_ago(weeks) Link
Returns a new date/time the specified number of weeks ago.
weeks_since(weeks) Link
Returns a new date/time the specified number of weeks in the future.
years_ago(years) Link
Returns a new date/time the specified number of years ago.
years_since(years) Link
Returns a new date/time the specified number of years in the future.
yesterday() Link
Returns a new date/time representing yesterday.