def this_week if today == "wednesday" return [date(sunday), ..., date(wednesday)] end end
def last_week return [date(last.sunday), ..., date(last.saturday)] end
答案 0 :(得分:1)
a_date.wday
给你the day of the week,你可以通过删除它来找到星期日。从那里,只需在数组中添加星期日和接下来的几天。在过去的一周里,只是该数组的每个元素减去7天。
require 'date'
def this_week(today)
sunday = today - today.wday
week = [sunday]
(1..6).each do |wday|
week << sunday + wday
end
return week
end
def last_week(today)
return this_week(today).map { |elem| elem - 7}
end