我正在开发一个使用ruby on rails的名册规划系统。
考虑到公司里有三个团队。每个小组都必须轮班工作。
例如,
"1/3/2017“是A队值班
"2/3/2017“是B组值班
"3/3/2017“是C组值班
“2017年4月3日”是A队值班
等等,
这是我的红宝石代码的一部分。
seed.rb
roster = Roster.create!(date: "1/03/2017", team: "A")
roster = Roster.create!(date: "2/03/2017", team: "B")
roster = Roster.create!(date: "3/03/2017", team: "C")
roster = Roster.create!(date: "4/03/2017", team: "A")然而,我想知道如何显示哪个团队在特定的一天值班,而这一天并没有通过计算存储在seed.rb中。
例如,
如何使系统显示哪个团队在"11/3/2017“和"15/3/2017”上值班?
发布于 2017-03-08 13:24:34
在这里使用像ice_cube (cube)这样的gem可能会有所帮助。然后,您可以轻松地设置递归规则和查询事件。
例如,对于三个团队,a, b, c
schedules = {}
start_date = Date.parse('1/3/2017')
%w[ a b c ].each_with_index do |team, index|
  schedules[team] = IceCube::Schedule.new(now = start_date + index) do |s|
    s.add_recurrence_rule(IceCube::Rule.daily(3))  # every 3 days
  end
end然后,您可以这样查询:
schedules['a'].first(3)
# => [2017-03-01 00:00:00 +0000, 2017-03-04 00:00:00 +0000, 2017-03-07 00:00:00 +0000]
schedules['b'].first(3)
# => [2017-03-02 00:00:00 +0000, 2017-03-05 00:00:00 +0000, 2017-03-08 00:00:00 +0000]https://stackoverflow.com/questions/42672306
复制相似问题