Archiving works
This commit is contained in:
		| @@ -3,6 +3,7 @@ package main | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| @@ -60,8 +61,30 @@ func getMostRecentTimeEntry() (*gime.TimeEntry, error) { | ||||
| } | ||||
|  | ||||
| func cmdDoArchive(args []string) int { | ||||
| 	fmt.Println("Not implemented yet.") | ||||
| 	return 1 | ||||
| 	if len(args) == 0 { | ||||
| 		fmt.Println("Nothing to do") | ||||
| 		return 1 | ||||
| 	} | ||||
| 	bef, err := parseFuzzyTime(args[0]) | ||||
| 	if err != nil { | ||||
| 		fmt.Println("Error parsing time") | ||||
| 		return 1 | ||||
| 	} | ||||
| 	ret := 0 | ||||
| 	fmt.Print("Archive all timers before ", bef) | ||||
| 	loadActiveAndRecentTimeEntries() | ||||
| 	for i := 0; i < timeEntries.Length(); i++ { | ||||
| 		tst := timeEntries.Get(i) | ||||
| 		if tst.GetEnd().Before(bef) { | ||||
| 			fmt.Print(".") | ||||
| 			if err = gdb.ArchiveTimeEntry(tst.GetUUID()); err != nil { | ||||
| 				fmt.Print("Error archiving entry (", tst.GetUUID(), ")", err.Error()) | ||||
| 				ret = 1 | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	fmt.Println("Done") | ||||
| 	return ret | ||||
| } | ||||
|  | ||||
| func cmdDoConfig(args []string) int { | ||||
| @@ -216,6 +239,33 @@ func cmdPrintList(args []string) int { | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func cmdListTags(args []string) int { | ||||
| 	loadActiveAndRecentTimeEntries() | ||||
| 	var allTags []string | ||||
| 	for i := 0; i < timeEntries.Length(); i++ { | ||||
| 		tc := timeEntries.Get(i).GetTags() | ||||
| 		for j := 0; j < tc.Length(); j++ { | ||||
| 			tg := tc.Get(j) | ||||
| 			var found bool | ||||
| 			for tst := range allTags { | ||||
| 				if allTags[tst] == tg { | ||||
| 					found = true | ||||
| 					break | ||||
| 				} | ||||
| 			} | ||||
| 			if !found { | ||||
| 				allTags = append(allTags, tg) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	sort.Sort(sort.StringSlice(allTags)) | ||||
| 	for i := range allTags { | ||||
| 		fmt.Println(allTags[i]) | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
|  | ||||
| func cmdPrintStatus(args []string) int { | ||||
| 	loadActiveTimeEntries() | ||||
| 	curr := time.Now() | ||||
| @@ -350,7 +400,7 @@ func initialize() { | ||||
|  | ||||
| 	opFuncs["archive"] = cmdDoArchive | ||||
| 	validOperations["archive"] = []string{ | ||||
| 		"archive                 - Archive all entries older than the archive date", | ||||
| 		"archive [date]          - Archive all entries older than the given date", | ||||
| 	} | ||||
|  | ||||
| 	opFuncs["fuzzyparse"] = cmdDoFuzzyParse | ||||
| @@ -359,6 +409,12 @@ func initialize() { | ||||
| 		"                          the RFC3339 result. (Basically for testing)", | ||||
| 	} | ||||
|  | ||||
| 	opFuncs["tags"] = cmdListTags | ||||
| 	validOperations["tags"] = []string{ | ||||
| 		"tags                    - List all tags that have been used in non-archived", | ||||
| 		"                          time entries", | ||||
| 	} | ||||
|  | ||||
| 	// Load the Config | ||||
| 	cfg, err = userConfig.NewConfig(AppName) | ||||
| 	if err != nil { | ||||
| @@ -384,6 +440,7 @@ func initialize() { | ||||
| 	} | ||||
|  | ||||
| 	fuzzyFormats = []string{ | ||||
| 		"1504", | ||||
| 		"15:04", // Kitchen, 24hr | ||||
| 		time.Kitchen, | ||||
| 		time.RFC3339, | ||||
| @@ -404,6 +461,10 @@ func initialize() { | ||||
| 		"20060102 15:04:05", | ||||
| 		"20060102 1504", | ||||
| 		"20060102 150405", | ||||
| 		"20060102T15:04", | ||||
| 		"20060102T15:04:05", | ||||
| 		"20060102T1504", | ||||
| 		"20060102T150405", | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user