snapshot.go

 1package bug
 2
 3import (
 4	"fmt"
 5	"time"
 6)
 7
 8// Snapshot is a compiled form of the Bug data structure used for storage and merge
 9type Snapshot struct {
10	id       string
11	Status   Status
12	Title    string
13	Comments []Comment
14	Labels   []Label
15}
16
17// Return the Bug identifier
18func (snap Snapshot) Id() string {
19	return snap.id
20}
21
22// Return the Bug identifier truncated for human consumption
23func (snap Snapshot) HumanId() string {
24	return fmt.Sprintf("%.8s", snap.id)
25}
26
27func (snap Snapshot) Summary() string {
28	return fmt.Sprintf("C:%d L:%d %s",
29		len(snap.Comments)-1,
30		len(snap.Labels),
31		snap.LastEdit().Format(time.RFC822),
32	)
33}
34
35func (snap Snapshot) LastEdit() time.Time {
36	if len(snap.Comments) == 0 {
37		return time.Unix(0, 0)
38	}
39	lastEditTimestamp := snap.Comments[len(snap.Comments)-1].Time
40	return time.Unix(lastEditTimestamp, 0)
41}