1package bug
 2
 3type BugsByCreationTime []*Bug
 4
 5func (b BugsByCreationTime) Len() int {
 6	return len(b)
 7}
 8
 9func (b BugsByCreationTime) Less(i, j int) bool {
10	if b[i].CreateLamportTime() < b[j].CreateLamportTime() {
11		return true
12	}
13
14	if b[i].CreateLamportTime() > b[j].CreateLamportTime() {
15		return false
16	}
17
18	// When the logical clocks are identical, that means we had a concurrent
19	// edition. In this case we rely on the timestamp. While the timestamp might
20	// be incorrect due to a badly set clock, the drift in sorting is bounded
21	// by the first sorting using the logical clock. That means that if users
22	// synchronize their bugs regularly, the timestamp will rarely be used, and
23	// should still provide a kinda accurate sorting when needed.
24	return b[i].FirstOp().Time().Before(b[j].FirstOp().Time())
25}
26
27func (b BugsByCreationTime) Swap(i, j int) {
28	b[i], b[j] = b[j], b[i]
29}
30
31type BugsByEditTime []*Bug
32
33func (b BugsByEditTime) Len() int {
34	return len(b)
35}
36
37func (b BugsByEditTime) Less(i, j int) bool {
38	if b[i].EditLamportTime() < b[j].EditLamportTime() {
39		return true
40	}
41
42	if b[i].EditLamportTime() > b[j].EditLamportTime() {
43		return false
44	}
45
46	// When the logical clocks are identical, that means we had a concurrent
47	// edition. In this case we rely on the timestamp. While the timestamp might
48	// be incorrect due to a badly set clock, the drift in sorting is bounded
49	// by the first sorting using the logical clock. That means that if users
50	// synchronize their bugs regularly, the timestamp will rarely be used, and
51	// should still provide a kinda accurate sorting when needed.
52	return b[i].LastOp().Time().Before(b[j].LastOp().Time())
53}
54
55func (b BugsByEditTime) Swap(i, j int) {
56	b[i], b[j] = b[j], b[i]
57}