Added full output to entry.GetOutput

This commit is contained in:
マリウス 2020-10-17 21:14:00 +01:00
parent 2ecc0a70ca
commit 6732d9634a
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F
2 changed files with 10 additions and 3 deletions

View file

@ -147,11 +147,18 @@ func (entry *Entry) GetOutputForFinish() (string) {
return fmt.Sprintf("%s finished tracking task%s\n", CharFinish, outputSuffix) return fmt.Sprintf("%s finished tracking task%s\n", CharFinish, outputSuffix)
} }
func (entry *Entry) GetOutput() (string) { func (entry *Entry) GetOutput(full bool) (string) {
var output string = ""
trackDiff := entry.Finish.Sub(entry.Begin) trackDiff := entry.Finish.Sub(entry.Begin)
trackDiffOut := time.Time{}.Add(trackDiff) trackDiffOut := time.Time{}.Add(trackDiff)
return fmt.Sprintf("%s %s on %s from %s to %s (%sh)", color.FgGray.Render(entry.ID), color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entry.Finish.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(trackDiffOut.Format("15:04"))) if full == false {
output = fmt.Sprintf("%s %s on %s from %s to %s (%sh)", color.FgGray.Render(entry.ID), color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entry.Finish.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(trackDiffOut.Format("15:04")))
} else {
output = fmt.Sprintf("%s\n %s on %s\n %sh from %s to %s\n\n Notes:\n %s\n", color.FgGray.Render(entry.ID), color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Project), color.FgLightWhite.Render(trackDiffOut.Format("15:04")), color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entry.Finish.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(strings.Replace(entry.Notes, "\n", "\n ", -1)) )
}
return output
} }
func GetFilteredEntries(entries []Entry, project string, task string, since time.Time, until time.Time) ([]Entry, error) { func GetFilteredEntries(entries []Entry, project string, task string, since time.Time, until time.Time) ([]Entry, error) {

View file

@ -54,7 +54,7 @@ var listCmd = &cobra.Command{
duration := entry.Finish.Sub(entry.Begin) duration := entry.Finish.Sub(entry.Begin)
durationDec := decimal.NewFromFloat(duration.Hours()) durationDec := decimal.NewFromFloat(duration.Hours())
totalHours = totalHours.Add(durationDec) totalHours = totalHours.Add(durationDec)
fmt.Printf("%s\n", entry.GetOutput()) fmt.Printf("%s\n", entry.GetOutput(false))
} }
if listTotalTime == true { if listTotalTime == true {