package exporter import ( "code.gitea.io/sdk/gitea" "encoding/csv" "os" "strconv" ) type LocalTrackedTimes gitea.TrackedTimes func (tt *LocalTrackedTimes) ToTableData() [][]string { data := make([][]string, 0) for _, t := range *tt { data = append(data, []string{t.Created.Format("02.01.2006 15:04"), strconv.FormatInt(t.UserID, 10), strconv.FormatInt(t.IssueID, 10), strconv.FormatInt(t.Time, 10)}) } return data } func (tt *LocalTrackedTimes) SaveToCSV(path string) (err error) { var file *os.File if file, err = os.Create(path); err != nil { return } defer file.Close() writer := csv.NewWriter(file) defer writer.Flush() err = writer.Write([]string{"Date", "User", "Issue", "Time (Seconds)"}) if err != nil { return } err = writer.WriteAll(tt.ToTableData()) if err != nil { return } return nil }