我想創建它獲得START_TIME和END_TIME和月份的數字應該分裂的開始時間和結束時間,並返回一個集合,我可以通過該循環,並保存到數據的API數據庫。例如每週星期日從14:05至18:30進行例如 。 這是我做了一切:splite日期Ice_Cube在軌
高清create_recurring_schedules 數= 0 如果反覆出現 時間表= Schedule.new(START_TIME,END_TIME:END_TIME)
schedule.add_recurrence_rule Rule.weekly
if month == 12
dates = schedule.occurrences_between(start_time, start_time + 1.year)
elsif month == 3
logger.info "################### The 3 month is #{self.s_month} #############################################"
dates = schedule.occurrences_between(start_time, start_time + 3.month)
elsif month == 6
logger.info "################### The 6 month is #{month} ###########################################"
dates = schedule.occurrences_between(start_time, start_time + 6.month)
elsif month == 1
dates = schedule.occurrences_between(start_time , start_time + 1.months)
end
dates.each do |date|
number +=1
logger.info "################### Start number #{number} #############################################"
ClinicSchedule.create(user_id: user_id, clinic_id: clinic_id, month: month,
start_time: date.start_time.strftime("%Y-%m-%d %H:%M"),
end_time: date.end_time.strftime("%Y-%m-%d %H:%M"),
date: date.strftime("%Y-%m-%d"), recurring: true,
recurrence_id: recurrence_id)
logger.info "################### Recurrence ID: "
logger.info recurrence_id
logger.info "################### End Recurrence ID ###########################################################"
end
end
end
,我面臨的問題是在這種情況下:
dates = schedule.occurrences_between(start_time , start_time + 1.months)
當我設置start_time從四個月後,例如2017-10-13 16:20。它只給了35周,並且不給出從四個月後開始的53周。
爲什麼要那樣做'Time.now + start_time'? – yzalavin
它是我這樣做了,START_TIME可兩個月後的最瘋狂的事情之一。當我用Time.now獨立它的工作很好,我這樣做是爲了看看發生了什麼 – Sandro