我需要解析第二天工作时间的开始,并以某种方式跳过周末。
DateTime.now.next_day.parse("9am")
无效,因为我无法在parse
上致电DateTime
而我无法在next_day
上致电Time
。
怎么做?
提前致谢:)
答案 0 :(得分:3)
检查周末:
unless Date.today.saturday? || Date.today.sunday?
# do stuff
end
第二天上午9点:
DateTime.now.next_day.change({hour: 9, minute: 0})
结帐:http://apidock.com/rails/DateTime/change(非常灵活)
您还可以考虑使用cron作业或调度程序或某种类型。也许发条:https://github.com/tomykaira/clockwork