HOLIDAYS = Schedule.new(Date.new(2012,1,1))
HOLIDAYS.add_recurrence_rule Rule.yearly.month_of_year(:october).day_of_month(31)
当我查看HOLIDAYS.occurs_on时?对于10/31/12,我得到假,但是当我检查10/30/12时,我得到了正确。
我做错了什么?
- 编辑 - 样本运行
days = Holidays::HALLOWEEN.occurrences(Date.today)
days.each do |day|
Log.info day
end
Log.info Holidays::HALLOWEEN.occurs_on?(Date.new(2012,10,31))
Log.info Holidays::HALLOWEEN.occurs_on?(Date.new(2012,10,30))
Log.info Holidays::HALLOWEEN.occurs_on?(Date.new(2013,10,31))
Log.info Holidays::HALLOWEEN.occurs_on?(Date.new(2013,10,30))
结果:
[09:22:15] INFO 2012-10-31 00:00:00 -0400
[09:22:15] INFO 2013-10-31 00:00:00 -0400
[09:22:15] INFO false
[09:22:15] INFO true
[09:22:15] INFO false
[09:22:15] INFO true
答案 0 :(得分:1)
通过从Date.new(2012,10,31)切换到Time.utc(2012,10,31),我得到了正确的行为。