3 Star 0 Fork 1

Gitee 极速下载/GoAlert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/target/goalert
克隆/下载
state_test.go 22.98 KB
一键复制 编辑 原始数据 按行查看 历史
Nathaniel Caza 提交于 2021-05-21 12:54 . move WeekdayFilter to timeutils
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
package oncall
import (
"testing"
"time"
"github.com/target/goalert/assignment"
"github.com/target/goalert/override"
"github.com/target/goalert/schedule"
"github.com/target/goalert/schedule/rotation"
"github.com/target/goalert/schedule/rule"
"github.com/target/goalert/util/timeutil"
)
func BenchmarkState_CalculateShifts(b *testing.B) {
s := &state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 0, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 0, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar2"),
}},
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("fooba4r"),
}},
{
Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.RotationTarget("fooba4r"),
},
Rotation: &ResolvedRotation{
Rotation: rotation.Rotation{
Type: rotation.TypeDaily,
ShiftLength: 2,
Start: time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC),
},
Users: []string{"a", "b", "c", "d", "e"},
},
},
{
Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.RotationTarget("fooba4r"),
},
Rotation: &ResolvedRotation{
Rotation: rotation.Rotation{
Type: rotation.TypeDaily,
ShiftLength: 2,
Start: time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC),
},
Users: []string{"a", "b", "c", "d", "e"},
},
},
{
Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.RotationTarget("fooba4r"),
},
Rotation: &ResolvedRotation{
Rotation: rotation.Rotation{
Type: rotation.TypeDaily,
ShiftLength: 2,
Start: time.Date(2017, 1, 2, 3, 4, 5, 6, time.UTC),
},
Users: []string{"a", "b", "c", "d", "e"},
},
},
},
overrides: []override.UserOverride{
{
AddUserID: "binbaz",
RemoveUserID: "foobar",
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
},
{
AddUserID: "binbaz2",
RemoveUserID: "foobar",
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
},
{
AddUserID: "binbaz",
RemoveUserID: "foob3ar",
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
},
},
}
s.CalculateShifts(
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
)
b.ResetTimer()
for i := 0; i < b.N; i++ {
s.CalculateShifts(
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2019, 1, 1, 8, 0, 0, 0, time.UTC), // 9:00AM
)
}
}
func TestResolvedRotation_UserID(t *testing.T) {
rot := &ResolvedRotation{
Rotation: rotation.Rotation{
ID: "rot",
Type: rotation.TypeWeekly,
Start: time.Date(2018, 4, 21, 14, 8, 9, 168379000, time.UTC),
ShiftLength: 6,
},
CurrentIndex: 0,
CurrentStart: time.Date(2018, 8, 30, 21, 54, 38, 334304000, time.UTC),
Users: []string{
"Javon Goodwin",
"Nora Bode",
"Coby Blanda",
"Clyde Reinger",
"Justina Moen",
"Herman Donnelly",
"Timmothy OReilly",
"Alvis Upton",
"Name Bayer",
"Daron Hirthe",
"Ismael Goodwin",
"Andrew Lockman",
"Adalberto Dare",
"Liliana Moen",
"Brant Abbott",
"Nia Purdy",
"Modesto Nolan",
"Angelica Leannon",
"Cleo Heaney",
"Osborne Batz",
"Lyda Christiansen",
"Loyal Green",
"Mose Lindgren",
"Camilla Stehr",
},
}
id := rot.UserID(time.Date(2018, 9, 10, 2, 44, 0, 0, time.UTC))
if id != "Javon Goodwin" {
t.Fatalf("got '%s'; want '%s'", id, "Javon Goodwin")
}
}
func TestState_CalculateShifts(t *testing.T) {
check := func(name string, start, end time.Time, s *state, exp []Shift) {
t.Helper()
t.Run(name, func(t *testing.T) {
t.Helper()
res := s.CalculateShifts(start, end)
for i, exp := range exp {
if i >= len(res) {
t.Errorf("shift[%d]: missing", i)
continue
}
if !res[i].Start.Equal(exp.Start) {
t.Errorf("shift[%d]: start = %s; want %s", i, res[i].Start.In(exp.Start.Location()), exp.Start)
}
if !res[i].End.Equal(exp.End) {
t.Errorf("shift[%d]: end = %s; want %s", i, res[i].End.In(exp.End.Location()), exp.End)
}
if res[i].Truncated != exp.Truncated {
t.Errorf("shift[%d]: truncated = %t; want %t", i, res[i].Truncated, exp.Truncated)
}
if res[i].UserID != exp.UserID {
t.Errorf("shift[%d]: userID = %s; want %s", i, res[i].UserID, exp.UserID)
}
}
if len(res) > len(exp) {
for _, res := range res[len(exp):] {
t.Errorf("extra shift: %v", res)
}
}
})
}
check("ActiveFuture",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
loc: time.UTC,
now: time.Date(2018, 1, 1, 7, 0, 0, 0, time.UTC),
history: []Shift{
{
UserID: "still-active",
Start: time.Date(2018, 1, 1, 6, 0, 0, 0, time.UTC),
},
{
UserID: "has-gap",
Start: time.Date(2018, 1, 1, 6, 0, 0, 0, time.UTC),
},
},
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(0, 0),
End: timeutil.NewClock(0, 0),
Target: assignment.UserTarget("still-active"),
}},
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{0, 1, 0, 0, 0, 0, 0},
Start: timeutil.NewClock(8, 30),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("has-gap"),
}},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 6, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "still-active",
},
{
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "has-gap",
},
},
)
check("HistoryRemainder",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
now: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
loc: time.UTC,
history: []Shift{
{
UserID: "foobar",
Start: time.Date(2018, 1, 1, 7, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 0, 0, 1, time.UTC), // will be truncated to 8
},
},
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
},
[]Shift{
// no shift is expected since it ended before/at the start time
},
)
check("Simple",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "foobar",
},
},
)
check("Temporary Schedule",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
tempScheds: []schedule.TemporarySchedule{
{
Start: time.Date(2018, 1, 1, 8, 15, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
Shifts: []schedule.FixedShift{{
Start: time.Date(2018, 1, 1, 8, 25, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 35, 0, 0, time.UTC),
UserID: "baz",
}},
},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 15, 0, 0, time.UTC),
Truncated: false,
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 1, 8, 25, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 35, 0, 0, time.UTC),
Truncated: false,
UserID: "baz",
},
{
Start: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "foobar",
},
},
)
check("SimpleWeek",
time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC),
time.Date(2018, 1, 8, 0, 0, 0, 0, time.UTC),
&state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(9, 0),
Target: assignment.UserTarget("foobar"),
}},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 2, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 2, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 3, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 3, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 4, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 4, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 5, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 5, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 6, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 6, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 7, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 7, 9, 0, 0, 0, time.UTC),
UserID: "foobar",
},
},
)
check("ReplaceOverride",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
overrides: []override.UserOverride{
{
AddUserID: "binbaz",
RemoveUserID: "foobar",
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
Truncated: false,
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
Truncated: false,
UserID: "binbaz",
},
{
Start: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "foobar",
},
},
)
check("AddOverride",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
overrides: []override.UserOverride{
{
AddUserID: "binbaz",
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
},
{
AddUserID: "binbaz",
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 15, 0, 0, time.UTC),
},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 15, 0, 0, time.UTC),
Truncated: false,
UserID: "binbaz",
},
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
Truncated: false,
UserID: "binbaz",
},
},
)
check("RemoveOverride",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
loc: time.UTC,
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
overrides: []override.UserOverride{
{
RemoveUserID: "foobar",
Start: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 8, 30, 0, 0, time.UTC),
Truncated: false,
UserID: "foobar",
},
{
Start: time.Date(2018, 1, 1, 8, 45, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "foobar",
},
},
)
check("History",
time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC), // 9:00AM
&state{
now: time.Date(2018, 1, 1, 8, 0, 0, 0, time.UTC),
loc: time.UTC,
history: []Shift{
{
UserID: "foobar",
Start: time.Date(2018, 1, 1, 7, 0, 0, 0, time.UTC), // user actually started at 7
},
},
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(10, 0),
Target: assignment.UserTarget("foobar"),
}},
},
},
[]Shift{
{
Start: time.Date(2018, 1, 1, 7, 0, 0, 0, time.UTC),
End: time.Date(2018, 1, 1, 9, 0, 0, 0, time.UTC),
Truncated: true,
UserID: "foobar",
},
},
)
check("Rotation",
time.Date(2018, 9, 10, 0, 0, 0, 0, time.UTC), // 8:00AM
time.Date(2018, 9, 17, 0, 0, 0, 0, time.UTC), // 9:00AM
&state{
now: time.Date(2018, 9, 10, 14, 44, 0, 0, time.UTC),
loc: time.UTC,
history: []Shift{
{
UserID: "Javon Goodwin",
Start: time.Date(2018, 9, 10, 2, 25, 0, 0, time.UTC),
End: time.Date(2018, 9, 10, 5, 29, 0, 0, time.UTC),
},
},
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 0, 0, 0},
Start: timeutil.NewClock(19, 40),
End: timeutil.NewClock(22, 53),
Target: assignment.RotationTarget("rot"),
},
Rotation: &ResolvedRotation{
Rotation: rotation.Rotation{
ID: "rot",
Type: rotation.TypeWeekly,
Start: time.Date(2018, 4, 21, 14, 8, 9, 168379000, time.UTC),
ShiftLength: 6,
},
CurrentIndex: 0,
CurrentStart: time.Date(2018, 8, 30, 21, 54, 38, 334304000, time.UTC),
Users: []string{
"Javon Goodwin",
"Nora Bode",
"Coby Blanda",
"Clyde Reinger",
"Justina Moen",
"Herman Donnelly",
"Timmothy OReilly",
"Alvis Upton",
"Name Bayer",
"Daron Hirthe",
"Ismael Goodwin",
"Andrew Lockman",
"Adalberto Dare",
"Liliana Moen",
"Brant Abbott",
"Nia Purdy",
"Modesto Nolan",
"Angelica Leannon",
"Cleo Heaney",
"Osborne Batz",
"Lyda Christiansen",
"Loyal Green",
"Mose Lindgren",
"Camilla Stehr",
},
},
},
},
},
[]Shift{
{
Start: time.Date(2018, 9, 10, 2, 25, 0, 0, time.UTC),
End: time.Date(2018, 9, 10, 5, 29, 0, 0, time.UTC),
Truncated: false,
UserID: "Javon Goodwin",
},
{
Start: time.Date(2018, 9, 10, 19, 40, 0, 0, time.UTC),
End: time.Date(2018, 9, 10, 22, 53, 0, 0, time.UTC),
Truncated: false,
UserID: "Javon Goodwin",
},
{
Start: time.Date(2018, 9, 11, 19, 40, 0, 0, time.UTC),
End: time.Date(2018, 9, 11, 22, 53, 0, 0, time.UTC),
Truncated: false,
UserID: "Javon Goodwin",
},
{
Start: time.Date(2018, 9, 12, 19, 40, 0, 0, time.UTC),
End: time.Date(2018, 9, 12, 22, 53, 0, 0, time.UTC),
Truncated: false,
UserID: "Javon Goodwin",
},
{
Start: time.Date(2018, 9, 16, 19, 40, 0, 0, time.UTC),
End: time.Date(2018, 9, 16, 22, 53, 0, 0, time.UTC),
Truncated: false,
UserID: "Javon Goodwin",
},
},
)
central, err := time.LoadLocation("America/Chicago")
if err != nil {
t.Fatal(err)
}
check(
"DailyRotation",
time.Date(2018, 9, 10, 0, 0, 0, 0, time.UTC),
time.Date(2018, 9, 17, 0, 0, 0, 0, time.UTC),
&state{
now: time.Date(2018, 9, 12, 10, 25, 0, 0, central),
loc: central,
history: []Shift{
{UserID: "Craig", Start: time.Date(2018, 9, 12, 13, 5, 0, 0, time.UTC)},
{UserID: "Caza", Start: time.Date(2018, 9, 12, 13, 0, 3, 0, time.UTC), End: time.Date(2018, 9, 12, 13, 1, 3, 0, time.UTC)},
{UserID: "Cook", Start: time.Date(2018, 9, 12, 1, 0, 3, 0, time.UTC), End: time.Date(2018, 9, 12, 13, 0, 3, 0, time.UTC)},
{UserID: "Aru", Start: time.Date(2018, 9, 11, 13, 0, 1, 0, time.UTC), End: time.Date(2018, 9, 12, 1, 1, 3, 0, time.UTC)},
{UserID: "Caza", Start: time.Date(2018, 9, 11, 1, 0, 1, 0, time.UTC), End: time.Date(2018, 9, 11, 13, 0, 1, 0, time.UTC)},
{UserID: "Donna", Start: time.Date(2018, 9, 10, 13, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 11, 1, 0, 1, 0, time.UTC)},
{UserID: "Cook", Start: time.Date(2018, 9, 10, 1, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 10, 13, 0, 0, 0, time.UTC)},
{UserID: "Craig", Start: time.Date(2018, 9, 9, 13, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 10, 1, 0, 0, 0, time.UTC)},
},
rules: []ResolvedRule{
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(8, 0),
End: timeutil.NewClock(20, 0),
Target: assignment.RotationTarget("rot-day"),
},
Rotation: &ResolvedRotation{
Rotation: rotation.Rotation{
ID: "rot-day",
Type: rotation.TypeDaily,
Start: time.Date(2018, 6, 15, 13, 0, 0, 0, time.UTC).In(central),
ShiftLength: 1,
},
CurrentIndex: 2,
CurrentStart: time.Date(2018, 9, 12, 13, 0, 3, 0, time.UTC),
Users: []string{
"Donna",
"Aru",
"Craig",
},
},
},
{Rule: rule.Rule{
WeekdayFilter: timeutil.WeekdayFilter{1, 1, 1, 1, 1, 1, 1},
Start: timeutil.NewClock(20, 0),
End: timeutil.NewClock(8, 0),
Target: assignment.RotationTarget("rot-night"),
},
Rotation: &ResolvedRotation{
Rotation: rotation.Rotation{
ID: "rot-night",
Type: rotation.TypeDaily,
Start: time.Date(2018, 6, 15, 13, 0, 0, 0, time.UTC),
ShiftLength: 1,
},
CurrentIndex: 0,
CurrentStart: time.Date(2018, 9, 12, 13, 0, 3, 0, time.UTC),
Users: []string{
"Caza",
"Cook",
},
},
},
},
},
[]Shift{
// history shifts
{UserID: "Craig", Start: time.Date(2018, 9, 9, 13, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 10, 1, 0, 0, 0, time.UTC)},
{UserID: "Cook", Start: time.Date(2018, 9, 10, 1, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 10, 13, 0, 0, 0, time.UTC)},
{UserID: "Donna", Start: time.Date(2018, 9, 10, 13, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 11, 1, 0, 0, 0, time.UTC)},
{UserID: "Caza", Start: time.Date(2018, 9, 11, 1, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 11, 13, 0, 0, 0, time.UTC)},
{UserID: "Aru", Start: time.Date(2018, 9, 11, 13, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 12, 1, 1, 0, 0, time.UTC)},
{UserID: "Cook", Start: time.Date(2018, 9, 12, 1, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 12, 13, 0, 0, 0, time.UTC)},
{UserID: "Caza", Start: time.Date(2018, 9, 12, 13, 0, 0, 0, time.UTC), End: time.Date(2018, 9, 12, 13, 1, 0, 0, time.UTC)},
// in-progress
{UserID: "Craig", Start: time.Date(2018, 9, 12, 13, 5, 0, 0, time.UTC), End: time.Date(2018, 9, 12, 20, 0, 0, 0, central)},
// future
{UserID: "Caza", Start: time.Date(2018, 9, 12, 20, 0, 0, 0, central), End: time.Date(2018, 9, 13, 8, 0, 0, 0, central)},
{UserID: "Donna", Start: time.Date(2018, 9, 13, 8, 0, 0, 0, central), End: time.Date(2018, 9, 13, 20, 0, 0, 0, central)},
{UserID: "Cook", Start: time.Date(2018, 9, 13, 20, 0, 0, 0, central), End: time.Date(2018, 9, 14, 8, 0, 0, 0, central)},
{UserID: "Aru", Start: time.Date(2018, 9, 14, 8, 0, 0, 0, central), End: time.Date(2018, 9, 14, 20, 0, 0, 0, central)},
{UserID: "Caza", Start: time.Date(2018, 9, 14, 20, 0, 0, 0, central), End: time.Date(2018, 9, 15, 8, 0, 0, 0, central)},
{UserID: "Craig", Start: time.Date(2018, 9, 15, 8, 0, 0, 0, central), End: time.Date(2018, 9, 15, 20, 0, 0, 0, central)},
{UserID: "Cook", Start: time.Date(2018, 9, 15, 20, 0, 0, 0, central), End: time.Date(2018, 9, 16, 8, 0, 0, 0, central)},
{UserID: "Donna", Start: time.Date(2018, 9, 16, 8, 0, 0, 0, central), End: time.Date(2018, 9, 16, 19, 0, 0, 0, central), Truncated: true},
},
)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/GoAlert.git
git@gitee.com:mirrors/GoAlert.git
mirrors
GoAlert
GoAlert
master

搜索帮助