- A
- B
- D
- E
- F
- L
- M
- N
- O
- P
- Q
- S
- T
- W
- Y
常量
| DAYS_INTO_WEEK | = | { sunday: 0, monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6 } |
| WEEKEND_DAYS | = | [ 6, 0 ] |
实例公共方法
after?(date_or_time) Link
如果日期/时间晚于 date_or_time,则返回 true。
all_week(start_day = Date.beginning_of_week) Link
返回表示当前日期/时间整周的 Range。一周从 start_day 开始,默认为 Date.beginning_of_week 或设置为 config.beginning_of_week。
before?(date_or_time) Link
如果日期/时间早于 date_or_time,则返回 true。
beginning_of_month() Link
返回一个表示月份开始的新日期/时间。
today = Date.today # => Thu, 18 Jun 2015 today.beginning_of_month # => Mon, 01 Jun 2015
DateTime 对象的时间将被设置为 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
返回一个表示季度开始的新日期/时间。
today = Date.today # => Fri, 10 Jul 2015 today.beginning_of_quarter # => Wed, 01 Jul 2015
DateTime 对象的时间将被设置为 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
返回一个表示本周开始日期的日期/时间。一周被假定从 start_day 开始,默认为 Date.beginning_of_week 或设置了 config.beginning_of_week。 DateTime 对象的时间将被设置为 0:00。
beginning_of_year() Link
返回一个表示年份开始的新日期/时间。
today = Date.today # => Fri, 10 Jul 2015 today.beginning_of_year # => Thu, 01 Jan 2015
DateTime 对象的时间将被设置为 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
返回指定天数前的日期/时间。
days_since(days) Link
返回指定天数后的日期/时间。
days_to_week_start(start_day = Date.beginning_of_week) Link
返回距离本周开始日期的天数。一周被假定从 start_day 开始,默认为 Date.beginning_of_week 或设置了 config.beginning_of_week。
end_of_quarter() Link
返回一个表示季度结束的新日期/时间。
today = Date.today # => Fri, 10 Jul 2015 today.end_of_quarter # => Wed, 30 Sep 2015
DateTime 对象的时间将被设置为 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
返回一个表示本周结束日期的日期/时间。一周被假定从 start_day 开始,默认为 Date.beginning_of_week 或设置了 config.beginning_of_week。 DateTime 对象的时间将被设置为 23:59:59。
future?() Link
如果日期/时间在未来,则返回 true。
last_month() Link
months_ago(1) 的简写。
last_year() Link
years_ago(1) 的简写。
months_ago(months) Link
返回指定月份前的日期/时间。
months_since(months) Link
返回指定月份后的日期/时间。
next_occurring(day_of_week) Link
返回指定星期几的下一个出现日期的日期/时间。
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
months_since(3) 的简写。
next_week(given_day_in_next_week = Date.beginning_of_week, same_time: false) Link
返回下周指定日期的日期/时间。
today = Date.today # => Thu, 07 May 2015 today.next_week # => Mon, 11 May 2015
given_day_in_next_week 默认为一周的开始,该开始日期由 Date.beginning_of_week 或设置的 config.beginning_of_week 确定。
today = Date.today # => Thu, 07 May 2015 today.next_week(:friday) # => Fri, 15 May 2015
DateTime 对象的时间被设置为 0:00,除非 same_time 为 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 200 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
返回下一个工作日的日期/时间。
on_weekday?() Link
如果日期/时间不是周六或周日,则返回 true。
on_weekend?() Link
如果日期/时间是周六或周日,则返回 true。
past?() Link
如果日期/时间在过去,则返回 true。
prev_occurring(day_of_week) Link
返回指定星期几的上一个出现日期的日期/时间。
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
返回上周指定日期的日期/时间。一周被假定从 start_day 开始,默认为 Date.beginning_of_week 或设置了 config.beginning_of_week。 DateTime 对象的时间将被设置为 0:00,除非 same_time 为 true。
# File activesupport/lib/active_support/core_ext/date_and_time/calculations.rb, line 223 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
quarter() Link
返回日期/时间的季度。
Date.new(2010, 1, 31).quarter # => 1 Date.new(2010, 4, 12).quarter # => 2 Date.new(2010, 9, 15).quarter # => 3 Date.new(2010, 12, 25).quarter # => 4
today?() Link
如果日期/时间是今天,则返回 true。
tomorrow() Link
返回明天的日期/时间。
weeks_ago(weeks) Link
返回指定周数前的日期/时间。
weeks_since(weeks) Link
返回指定周数后的日期/时间。
years_ago(years) Link
返回指定年数前的日期/时间。
years_since(years) Link
返回指定年数后的日期/时间。
yesterday() Link
返回昨天的日期/时间。