Update .editorconfig, run gofumpt -w ./

This commit is contained in:
マリウス
2025-02-19 10:32:24 -05:00
parent d6f9f8efeb
commit 866ee4ac6d
28 changed files with 1735 additions and 1727 deletions
-2
View File
@@ -4,8 +4,6 @@ root = true
end_of_line = lf end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
indent_style = space
indent_size = 2
insert_final_newline = true insert_final_newline = true
max_line = 80 max_line = 80
+11 -10
View File
@@ -2,17 +2,18 @@ package z
import ( import (
"fmt" "fmt"
"time"
"strings" "strings"
"github.com/shopspring/decimal" "time"
"github.com/jinzhu/now" "github.com/jinzhu/now"
"github.com/shopspring/decimal"
// "github.com/gookit/color" // "github.com/gookit/color"
) )
type Statistic struct { type Statistic struct {
Hours decimal.Decimal Hours decimal.Decimal
Project string Project string
Color (func(...interface {}) string) Color (func(...interface{}) string)
} }
type WeekStatistics map[string][]Statistic type WeekStatistics map[string][]Statistic
@@ -123,7 +124,7 @@ func NewCalendar(entries []Entry) (Calendar, error) {
cal.Months[month0].Weeks[weeknumber0].Statistics[weekdayName] = append(cal.Months[month0].Weeks[weeknumber0].Statistics[weekdayName], stat) cal.Months[month0].Weeks[weeknumber0].Statistics[weekdayName] = append(cal.Months[month0].Weeks[weeknumber0].Statistics[weekdayName], stat)
} }
var dist = cal.Distribution[entry.Project] dist := cal.Distribution[entry.Project]
dist.Project = entry.Project dist.Project = entry.Project
dist.Hours = dist.Hours.Add(sameDayHours) dist.Hours = dist.Hours.Add(sameDayHours)
dist.Hours = dist.Hours.Add(nextDayHours) dist.Hours = dist.Hours.Add(nextDayHours)
@@ -138,14 +139,14 @@ func NewCalendar(entries []Entry) (Calendar, error) {
return cal, nil return cal, nil
} }
func (calendar *Calendar) GetOutputForWeekCalendar(date time.Time, month int, week int) (string) { func (calendar *Calendar) GetOutputForWeekCalendar(date time.Time, month int, week int) string {
var output string = "" var output string = ""
var bars [][]string var bars [][]string
var totalHours = decimal.NewFromInt(0) totalHours := decimal.NewFromInt(0)
var days = []string{"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"} days := []string{"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}
for _, day := range days { for _, day := range days {
var dayHours = decimal.NewFromInt(0) dayHours := decimal.NewFromInt(0)
for _, stat := range calendar.Months[month].Weeks[week].Statistics[day] { for _, stat := range calendar.Months[month].Weeks[week].Statistics[day] {
dayHours = dayHours.Add(stat.Hours) dayHours = dayHours.Add(stat.Hours)
@@ -153,7 +154,7 @@ func (calendar *Calendar) GetOutputForWeekCalendar(date time.Time, month int, we
} }
if dayHours.GreaterThan(decimal.NewFromInt(24)) { if dayHours.GreaterThan(decimal.NewFromInt(24)) {
fmt.Printf("%s %s of week %d in month %d has more than 24h tracked; cutting at 24h now\n", CharError, day, (month+1), (week+1)) fmt.Printf("%s %s of week %d in month %d has more than 24h tracked; cutting at 24h now\n", CharError, day, (month + 1), (week + 1))
dayHours = decimal.NewFromInt(24) dayHours = decimal.NewFromInt(24)
} }
@@ -175,7 +176,7 @@ func (calendar *Calendar) GetOutputForWeekCalendar(date time.Time, month int, we
return output return output
} }
func (calendar *Calendar) GetOutputForDistribution() (string) { func (calendar *Calendar) GetOutputForDistribution() string {
var output string = "" var output string = ""
// fmt.Printf("%s\n", calendar.TotalHours.String()) // fmt.Printf("%s\n", calendar.TotalHours.String())
-1
View File
@@ -16,4 +16,3 @@ const (
FinishWithMetadata int = 0 FinishWithMetadata int = 0
FinishOnlyTime int = 1 FinishOnlyTime int = 1
) )
+21 -21
View File
@@ -8,8 +8,8 @@ import (
"strings" "strings"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/tidwall/buntdb"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/tidwall/buntdb"
) )
type Database struct { type Database struct {
@@ -34,7 +34,7 @@ func InitDatabase() (*Database, error) {
return &database, nil return &database, nil
} }
func (database *Database) NewID() (string) { func (database *Database) NewID() string {
id, err := uuid.NewRandom() id, err := uuid.NewRandom()
if err != nil { if err != nil {
log.Fatalln("could not generate UUID: %+v", err) log.Fatalln("could not generate UUID: %+v", err)
@@ -52,12 +52,12 @@ func (database *Database) AddEntry(user string, entry Entry, setRunning bool) (s
dberr := database.DB.Update(func(tx *buntdb.Tx) error { dberr := database.DB.Update(func(tx *buntdb.Tx) error {
if setRunning == true { if setRunning == true {
_, _, seterr := tx.Set(user + ":status:running", id, nil) _, _, seterr := tx.Set(user+":status:running", id, nil)
if seterr != nil { if seterr != nil {
return seterr return seterr
} }
} }
_, _, seterr := tx.Set(user + ":entry:" + id, string(entryJson), nil) _, _, seterr := tx.Set(user+":entry:"+id, string(entryJson), nil)
if seterr != nil { if seterr != nil {
return seterr return seterr
} }
@@ -92,7 +92,7 @@ func (database *Database) UpdateEntry(user string, entry Entry) (string, error)
} }
dberr := database.DB.Update(func(tx *buntdb.Tx) error { dberr := database.DB.Update(func(tx *buntdb.Tx) error {
_, _, seerr := tx.Set(user + ":entry:" + entry.ID, string(entryJson), nil) _, _, seerr := tx.Set(user+":entry:"+entry.ID, string(entryJson), nil)
if seerr != nil { if seerr != nil {
return seerr return seerr
} }
@@ -119,12 +119,12 @@ func (database *Database) FinishEntry(user string, entry Entry) (string, error)
return errors.New("specified entry is not currently running!") return errors.New("specified entry is not currently running!")
} }
_, _, srerr := tx.Set(user + ":status:running", "", nil) _, _, srerr := tx.Set(user+":status:running", "", nil)
if srerr != nil { if srerr != nil {
return srerr return srerr
} }
_, _, seerr := tx.Set(user + ":entry:" + entry.ID, string(entryJson), nil) _, _, seerr := tx.Set(user+":entry:"+entry.ID, string(entryJson), nil)
if seerr != nil { if seerr != nil {
return seerr return seerr
} }
@@ -135,7 +135,7 @@ func (database *Database) FinishEntry(user string, entry Entry) (string, error)
return entry.ID, dberr return entry.ID, dberr
} }
func (database *Database) EraseEntry(user string, id string) (error) { func (database *Database) EraseEntry(user string, id string) error {
runningEntryId, err := database.GetRunningEntryId(user) runningEntryId, err := database.GetRunningEntryId(user)
if err != nil { if err != nil {
return err return err
@@ -143,7 +143,7 @@ func (database *Database) EraseEntry(user string, id string) (error) {
dberr := database.DB.Update(func(tx *buntdb.Tx) error { dberr := database.DB.Update(func(tx *buntdb.Tx) error {
if runningEntryId == id { if runningEntryId == id {
_, _, seterr := tx.Set(user + ":status:running", "", nil) _, _, seterr := tx.Set(user+":status:running", "", nil)
if seterr != nil { if seterr != nil {
return seterr return seterr
} }
@@ -182,7 +182,7 @@ func (database *Database) ListEntries(user string) ([]Entry, error) {
var entries []Entry var entries []Entry
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
tx.AscendKeys(user + ":entry:*", func(key, value string) bool { tx.AscendKeys(user+":entry:*", func(key, value string) bool {
var entry Entry var entry Entry
json.Unmarshal([]byte(value), &entry) json.Unmarshal([]byte(value), &entry)
@@ -200,10 +200,10 @@ func (database *Database) ListEntries(user string) ([]Entry, error) {
} }
func (database *Database) GetImportsSHA1List(user string) (map[string]string, error) { func (database *Database) GetImportsSHA1List(user string) (map[string]string, error) {
var sha1List = make(map[string]string) sha1List := make(map[string]string)
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
value, err := tx.Get(user + ":imports:sha1", false) value, err := tx.Get(user+":imports:sha1", false)
if err != nil { if err != nil {
return nil return nil
} }
@@ -223,17 +223,17 @@ func (database *Database) GetImportsSHA1List(user string) (map[string]string, er
return sha1List, dberr return sha1List, dberr
} }
func (database *Database) UpdateImportsSHA1List(user string, sha1List map[string]string) (error) { func (database *Database) UpdateImportsSHA1List(user string, sha1List map[string]string) error {
var sha1Entries []string var sha1Entries []string
for sha1, id := range sha1List { for sha1, id := range sha1List {
sha1Entries = append(sha1Entries, sha1 + ":" + id) sha1Entries = append(sha1Entries, sha1+":"+id)
} }
value := strings.Join(sha1Entries, ",") value := strings.Join(sha1Entries, ",")
dberr := database.DB.Update(func(tx *buntdb.Tx) error { dberr := database.DB.Update(func(tx *buntdb.Tx) error {
_, _, seterr := tx.Set(user + ":imports:sha1", value, nil) _, _, seterr := tx.Set(user+":imports:sha1", value, nil)
if seterr != nil { if seterr != nil {
return seterr return seterr
} }
@@ -244,7 +244,7 @@ func (database *Database) UpdateImportsSHA1List(user string, sha1List map[string
return dberr return dberr
} }
func (database *Database) UpdateProject(user string, projectName string, project Project) (error) { func (database *Database) UpdateProject(user string, projectName string, project Project) error {
projectJson, jsonerr := json.Marshal(project) projectJson, jsonerr := json.Marshal(project)
if jsonerr != nil { if jsonerr != nil {
return jsonerr return jsonerr
@@ -253,7 +253,7 @@ func (database *Database) UpdateProject(user string, projectName string, project
projectId := GetIdFromName(projectName) projectId := GetIdFromName(projectName)
dberr := database.DB.Update(func(tx *buntdb.Tx) error { dberr := database.DB.Update(func(tx *buntdb.Tx) error {
_, _, sperr := tx.Set(user + ":project:" + projectId, string(projectJson), nil) _, _, sperr := tx.Set(user+":project:"+projectId, string(projectJson), nil)
if sperr != nil { if sperr != nil {
return sperr return sperr
} }
@@ -269,7 +269,7 @@ func (database *Database) GetProject(user string, projectName string) (Project,
projectId := GetIdFromName(projectName) projectId := GetIdFromName(projectName)
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
value, err := tx.Get(user + ":project:" + projectId, false) value, err := tx.Get(user+":project:"+projectId, false)
if err != nil { if err != nil {
return nil return nil
} }
@@ -282,7 +282,7 @@ func (database *Database) GetProject(user string, projectName string) (Project,
return project, dberr return project, dberr
} }
func (database *Database) UpdateTask(user string, taskName string, task Task) (error) { func (database *Database) UpdateTask(user string, taskName string, task Task) error {
taskJson, jsonerr := json.Marshal(task) taskJson, jsonerr := json.Marshal(task)
if jsonerr != nil { if jsonerr != nil {
return jsonerr return jsonerr
@@ -291,7 +291,7 @@ func (database *Database) UpdateTask(user string, taskName string, task Task) (e
taskId := GetIdFromName(taskName) taskId := GetIdFromName(taskName)
dberr := database.DB.Update(func(tx *buntdb.Tx) error { dberr := database.DB.Update(func(tx *buntdb.Tx) error {
_, _, sperr := tx.Set(user + ":task:" + taskId, string(taskJson), nil) _, _, sperr := tx.Set(user+":task:"+taskId, string(taskJson), nil)
if sperr != nil { if sperr != nil {
return sperr return sperr
} }
@@ -307,7 +307,7 @@ func (database *Database) GetTask(user string, taskName string) (Task, error) {
taskId := GetIdFromName(taskName) taskId := GetIdFromName(taskName)
dberr := database.DB.View(func(tx *buntdb.Tx) error { dberr := database.DB.View(func(tx *buntdb.Tx) error {
value, err := tx.Get(user + ":task:" + taskId, false) value, err := tx.Get(user+":task:"+taskId, false)
if err != nil { if err != nil {
return nil return nil
} }
+12 -12
View File
@@ -2,9 +2,10 @@ package z
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"time" "time"
"fmt"
"github.com/gookit/color" "github.com/gookit/color"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
"github.com/spf13/viper" "github.com/spf13/viper"
@@ -28,7 +29,8 @@ func NewEntry(
finish string, finish string,
project string, project string,
task string, task string,
user string) (Entry, error) { user string,
) (Entry, error) {
var err error var err error
newEntry := Entry{} newEntry := Entry{}
@@ -55,7 +57,7 @@ func NewEntry(
return newEntry, nil return newEntry, nil
} }
func (entry *Entry) SetIDFromDatabaseKey(key string) (error) { func (entry *Entry) SetIDFromDatabaseKey(key string) error {
splitKey := strings.Split(key, ":") splitKey := strings.Split(key, ":")
if len(splitKey) < 3 || len(splitKey) > 3 { if len(splitKey) < 3 || len(splitKey) > 3 {
@@ -100,11 +102,11 @@ func (entry *Entry) SetFinishFromString(finish string, contextTime time.Time) (t
return entry.Finish, nil return entry.Finish, nil
} }
func (entry *Entry) IsFinishedAfterBegan() (bool) { func (entry *Entry) IsFinishedAfterBegan() bool {
return (entry.Finish.IsZero() || entry.Begin.Before(entry.Finish) || entry.Begin.Equal(entry.Finish)) return (entry.Finish.IsZero() || entry.Begin.Before(entry.Finish) || entry.Begin.Equal(entry.Finish))
} }
func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string) { func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) string {
var outputPrefix string = "" var outputPrefix string = ""
var outputSuffix string = "" var outputSuffix string = ""
@@ -132,15 +134,15 @@ func (entry *Entry) GetOutputForTrack(isRunning bool, wasRunning bool) (string)
return fmt.Sprintf("%s %s task%s\n", CharTrack, outputPrefix, outputSuffix) return fmt.Sprintf("%s %s task%s\n", CharTrack, outputPrefix, outputSuffix)
} }
func (entry *Entry) GetDuration() (decimal.Decimal) { func (entry *Entry) GetDuration() decimal.Decimal {
duration := entry.Finish.Sub(entry.Begin) duration := entry.Finish.Sub(entry.Begin)
if (duration < 0) { if duration < 0 {
duration = time.Now().Sub(entry.Begin) duration = time.Now().Sub(entry.Begin)
} }
return decimal.NewFromFloat(duration.Hours()) return decimal.NewFromFloat(duration.Hours())
} }
func (entry *Entry) GetOutputForFinish() (string) { func (entry *Entry) GetOutputForFinish() string {
var outputSuffix string = "" var outputSuffix string = ""
trackDiff := entry.Finish.Sub(entry.Begin) trackDiff := entry.Finish.Sub(entry.Begin)
@@ -159,7 +161,7 @@ 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(full bool) (string) { func (entry *Entry) GetOutput(full bool) string {
var output string = "" var output string = ""
var entryFinish time.Time var entryFinish time.Time
var isRunning string = "" var isRunning string = ""
@@ -174,14 +176,13 @@ func (entry *Entry) GetOutput(full bool) (string) {
trackDiff := entryFinish.Sub(entry.Begin) trackDiff := entryFinish.Sub(entry.Begin)
taskDuration := fmtDuration(trackDiff) taskDuration := fmtDuration(trackDiff)
if full == false { if full == false {
output = fmt.Sprintf("%s %s on %s from %s to %s (%sh) %s", output = fmt.Sprintf("%s %s on %s from %s to %s (%sh) %s",
color.FgGray.Render(entry.ID), color.FgGray.Render(entry.ID),
color.FgLightWhite.Render(entry.Task), color.FgLightWhite.Render(entry.Task),
color.FgLightWhite.Render(entry.Project), color.FgLightWhite.Render(entry.Project),
color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entry.Begin.Format("2006-01-02 15:04 -0700")),
color.FgLightWhite.Render(entryFinish.Format("2006-01-02 15:04 -0700")), color.FgLightWhite.Render(entryFinish.Format("2006-01-02 15:04 -0700")),
color.FgLightWhite.Render(taskDuration) , color.FgLightWhite.Render(taskDuration),
color.FgLightYellow.Render(isRunning), color.FgLightYellow.Render(isRunning),
) )
} else { } else {
@@ -237,4 +238,3 @@ func (entry *Entry) secondsFinish() {
entry.Finish = entry.Finish.Truncate(time.Duration(time.Minute)) entry.Finish = entry.Finish.Truncate(time.Duration(time.Minute))
} }
} }
+3 -2
View File
@@ -1,10 +1,11 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"github.com/spf13/cobra" "os"
"github.com/gookit/color" "github.com/gookit/color"
"github.com/spf13/cobra"
) )
var eraseCmd = &cobra.Command{ var eraseCmd = &cobra.Command{
+6 -5
View File
@@ -1,10 +1,11 @@
package z package z
import ( import (
"os"
"fmt"
"strings"
"encoding/json" "encoding/json"
"fmt"
"os"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -53,7 +54,7 @@ var exportCmd = &cobra.Command{
} }
var output string = "" var output string = ""
switch(format) { switch format {
case "zeit": case "zeit":
output, err = exportZeitJson(user, filteredEntries) output, err = exportZeitJson(user, filteredEntries)
if err != nil { if err != nil {
@@ -81,7 +82,7 @@ func init() {
exportCmd.Flags().StringVar(&format, "format", "zeit", "Format to export, possible values: zeit, tyme") exportCmd.Flags().StringVar(&format, "format", "zeit", "Format to export, possible values: zeit, tyme")
exportCmd.Flags().StringVar(&since, "since", "", "Date/time to start the export from") exportCmd.Flags().StringVar(&since, "since", "", "Date/time to start the export from")
exportCmd.Flags().StringVar(&until, "until", "", "Date/time to export until") exportCmd.Flags().StringVar(&until, "until", "", "Date/time to export until")
exportCmd.Flags().StringVar(&listRange, "range", "", "Shortcut for --since and --until that accepts: " + strings.Join(Ranges(), ", ")) exportCmd.Flags().StringVar(&listRange, "range", "", "Shortcut for --since and --until that accepts: "+strings.Join(Ranges(), ", "))
exportCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be exported") exportCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be exported")
exportCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be exported") exportCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be exported")
+19 -21
View File
@@ -1,21 +1,21 @@
package z package z
import ( import (
"os/user"
"os/exec"
"bytes" "bytes"
"errors"
"fmt"
"math"
"os"
"os/exec"
"os/user"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"math"
"errors"
"fmt"
"os"
"github.com/araddon/dateparse" "github.com/araddon/dateparse"
"github.com/spf13/viper"
"github.com/jinzhu/now" "github.com/jinzhu/now"
"github.com/spf13/viper"
) )
func TimeFormats() []string { func TimeFormats() []string {
@@ -27,7 +27,7 @@ func TimeFormats() []string {
} }
} }
func GetCurrentUser() (string) { func GetCurrentUser() string {
user, err := user.Current() user, err := user.Current()
if err != nil { if err != nil {
return "unknown" return "unknown"
@@ -36,7 +36,7 @@ func GetCurrentUser() (string) {
return user.Username return user.Username
} }
func GetTimeFormat(timeStr string) (int) { func GetTimeFormat(timeStr string) int {
var matched bool var matched bool
var regerr error var regerr error
@@ -56,7 +56,7 @@ func GetTimeFormat(timeStr string) (int) {
// TODO: Use https://golang.org/pkg/time/#ParseDuration // TODO: Use https://golang.org/pkg/time/#ParseDuration
func RelToTime(timeStr string, ftId int, contextTime time.Time) (time.Time, error) { func RelToTime(timeStr string, ftId int, contextTime time.Time) (time.Time, error) {
var re = regexp.MustCompile(TimeFormats()[ftId]) re := regexp.MustCompile(TimeFormats()[ftId])
gm := re.FindStringSubmatch(timeStr) gm := re.FindStringSubmatch(timeStr)
if len(gm) < 4 { if len(gm) < 4 {
@@ -67,7 +67,7 @@ func RelToTime(timeStr string, ftId int, contextTime time.Time) (time.Time, erro
var minutes int = 0 var minutes int = 0
if ftId == TFRelHourFraction { if ftId == TFRelHourFraction {
f, _ := strconv.ParseFloat(gm[2] + "." + gm[3], 32) f, _ := strconv.ParseFloat(gm[2]+"."+gm[3], 32)
minutes = int(f * 60.0) minutes = int(f * 60.0)
} else { } else {
hours, _ = strconv.Atoi(gm[2]) hours, _ = strconv.Atoi(gm[2])
@@ -79,9 +79,9 @@ func RelToTime(timeStr string, ftId int, contextTime time.Time) (time.Time, erro
if viper.IsSet("time.relative") && viper.GetString("time.relative") == "context" && !contextTime.IsZero() { if viper.IsSet("time.relative") && viper.GetString("time.relative") == "context" && !contextTime.IsZero() {
switch gm[1] { switch gm[1] {
case "+": case "+":
t = contextTime.Add(time.Hour * time.Duration(hours) + time.Minute * time.Duration(minutes)) t = contextTime.Add(time.Hour*time.Duration(hours) + time.Minute*time.Duration(minutes))
case "-": case "-":
t = contextTime.Add((time.Hour * time.Duration(hours) + time.Minute * time.Duration(minutes)) * -1) t = contextTime.Add((time.Hour*time.Duration(hours) + time.Minute*time.Duration(minutes)) * -1)
} }
return t, nil return t, nil
@@ -89,9 +89,9 @@ func RelToTime(timeStr string, ftId int, contextTime time.Time) (time.Time, erro
switch gm[1] { switch gm[1] {
case "+": case "+":
t = time.Now().Local().Add(time.Hour * time.Duration(hours) + time.Minute * time.Duration(minutes)) t = time.Now().Local().Add(time.Hour*time.Duration(hours) + time.Minute*time.Duration(minutes))
case "-": case "-":
t = time.Now().Local().Add((time.Hour * time.Duration(hours) + time.Minute * time.Duration(minutes)) * -1) t = time.Now().Local().Add((time.Hour*time.Duration(hours) + time.Minute*time.Duration(minutes)) * -1)
} }
return t, nil return t, nil
@@ -100,7 +100,7 @@ func RelToTime(timeStr string, ftId int, contextTime time.Time) (time.Time, erro
func ParseTime(timeStr string, contextTime time.Time) (time.Time, error) { func ParseTime(timeStr string, contextTime time.Time) (time.Time, error) {
tfId := GetTimeFormat(timeStr) tfId := GetTimeFormat(timeStr)
t:= time.Now() t := time.Now()
switch tfId { switch tfId {
case TFAbsTwelveHour: case TFAbsTwelveHour:
@@ -115,7 +115,6 @@ func ParseTime(timeStr string, contextTime time.Time) (time.Time, error) {
return RelToTime(timeStr, tfId, contextTime) return RelToTime(timeStr, tfId, contextTime)
default: default:
loc, err := time.LoadLocation("Local") loc, err := time.LoadLocation("Local")
if err != nil { if err != nil {
return time.Now(), errors.New("could not load location") return time.Now(), errors.New("could not load location")
} }
@@ -142,8 +141,8 @@ func GetIdFromName(name string) string {
return id return id
} }
func GetISOCalendarWeek(date time.Time) (int) { func GetISOCalendarWeek(date time.Time) int {
var _, cw = date.ISOWeek() _, cw := date.ISOWeek()
return cw return cw
} }
@@ -156,7 +155,7 @@ func GetISOWeekInMonth(date time.Time) (month int, weeknumber int) {
addDay := (date.Day() - newDay) * -1 addDay := (date.Day() - newDay) * -1
changedDate := date.AddDate(0, 0, addDay) changedDate := date.AddDate(0, 0, addDay)
return int(changedDate.Month()), int(math.Ceil(float64(changedDate.Day()) / 7.0)); return int(changedDate.Month()), int(math.Ceil(float64(changedDate.Day()) / 7.0))
} }
func GetGitLog(repo string, since time.Time, until time.Time) (string, string, error) { func GetGitLog(repo string, since time.Time, until time.Time) (string, string, error) {
@@ -200,7 +199,6 @@ func Ranges() []string {
} }
func ParseSinceUntil(since string, until string, listRange string) (time.Time, time.Time) { func ParseSinceUntil(since string, until string, listRange string) (time.Time, time.Time) {
var sinceTime time.Time var sinceTime time.Time
var untilTime time.Time var untilTime time.Time
var err error var err error
+5 -4
View File
@@ -1,12 +1,13 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"os"
"time" "time"
"github.com/spf13/cobra"
"github.com/gookit/color"
"github.com/cnf/structhash" "github.com/cnf/structhash"
"github.com/gookit/color"
"github.com/spf13/cobra"
) )
func importTymeJson(user string, file string) ([]Entry, error) { func importTymeJson(user string, file string) ([]Entry, error) {
@@ -57,7 +58,7 @@ var importCmd = &cobra.Command{
user := GetCurrentUser() user := GetCurrentUser()
switch(format) { switch format {
case "zeit": case "zeit":
// TODO: // TODO:
fmt.Printf("%s not yet implemented\n", CharError) fmt.Printf("%s not yet implemented\n", CharError)
+8 -8
View File
@@ -8,18 +8,18 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var listTotalTime bool var (
var listOnlyProjectsAndTasks bool listTotalTime bool
var listOnlyTasks bool listOnlyProjectsAndTasks bool
var appendProjectIDToTask bool listOnlyTasks bool
appendProjectIDToTask bool
)
var listCmd = &cobra.Command{ var listCmd = &cobra.Command{
Use: "list", Use: "list",
Short: "List activities", Short: "List activities",
Long: "List all tracked activities.", Long: "List all tracked activities.",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
filteredEntries := listEntries() filteredEntries := listEntries()
totalHours := decimal.NewFromInt(0) totalHours := decimal.NewFromInt(0)
@@ -29,7 +29,7 @@ var listCmd = &cobra.Command{
} }
if listTotalTime == true { if listTotalTime == true {
fmt.Printf("\nTOTAL: %s H\n\n", fmtHours(totalHours)); fmt.Printf("\nTOTAL: %s H\n\n", fmtHours(totalHours))
} }
return return
}, },
@@ -39,7 +39,7 @@ func init() {
rootCmd.AddCommand(listCmd) rootCmd.AddCommand(listCmd)
listCmd.Flags().StringVar(&since, "since", "", "Date/time to start the list from") listCmd.Flags().StringVar(&since, "since", "", "Date/time to start the list from")
listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until") listCmd.Flags().StringVar(&until, "until", "", "Date/time to list until")
listCmd.Flags().StringVar(&listRange, "range", "", "Shortcut for --since and --until that accepts: " + strings.Join(Ranges(), ", ")) listCmd.Flags().StringVar(&listRange, "range", "", "Shortcut for --since and --until that accepts: "+strings.Join(Ranges(), ", "))
listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed") listCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be listed")
listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed") listCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be listed")
listCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes") listCmd.Flags().BoolVar(&fractional, "decimal", false, "Show fractional hours in decimal format instead of minutes")
-3
View File
@@ -1,8 +1,5 @@
package z package z
import (
)
type Project struct { type Project struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Color string `json:"color,omitempty"` Color string `json:"color,omitempty"`
+1 -1
View File
@@ -1,8 +1,8 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"os"
// "time" // "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
// "github.com/gookit/color" // "github.com/gookit/color"
+26 -17
View File
@@ -2,33 +2,42 @@ package z
import ( import (
"fmt" "fmt"
"os"
"github.com/gookit/color"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/gookit/color"
"os"
) )
var database *Database var database *Database
var begin string var (
var finish string begin string
var switchString string finish string
var project string switchString string
var task string project string
var notes string task string
notes string
)
var since string var (
var until string since string
var listRange string until string
listRange string
)
var format string var (
var force bool format string
force bool
)
var noColors bool var (
var debug bool noColors bool
var cfgFile string debug bool
cfgFile string
)
const( const (
CharTrack = " ▶" CharTrack = " ▶"
CharFinish = " ■" CharFinish = " ■"
CharErase = " ◀" CharErase = " ◀"
+3 -2
View File
@@ -1,10 +1,11 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"time" "os"
"strings" "strings"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
// "github.com/shopspring/decimal" // "github.com/shopspring/decimal"
// "github.com/gookit/color" // "github.com/gookit/color"
-1
View File
@@ -9,7 +9,6 @@ var switchBackCmd = &cobra.Command{
Short: "switchback to the task before the last one", Short: "switchback to the task before the last one",
Long: "End running activity and resume the task which was before, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.", Long: "End running activity and resume the task which was before, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
finish = switchString finish = switchString
finishTask(FinishOnlyTime) finishTask(FinishOnlyTime)
-2
View File
@@ -9,7 +9,6 @@ var switchCmd = &cobra.Command{
Short: "switch to another task", Short: "switch to another task",
Long: "End running activity and track new activity, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.", Long: "End running activity and track new activity, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
finish = switchString finish = switchString
finishTask(FinishOnlyTime) finishTask(FinishOnlyTime)
@@ -35,4 +34,3 @@ func init() {
return tasks, cobra.ShellCompDirectiveDefault return tasks, cobra.ShellCompDirectiveDefault
}) })
} }
+1 -5
View File
@@ -39,7 +39,6 @@ func listEntries() []Entry {
} }
func printProjects(entries []Entry) { func printProjects(entries []Entry) {
projectsAndTasks, _ := listProjectsAndTasks(entries) projectsAndTasks, _ := listProjectsAndTasks(entries)
for project := range projectsAndTasks { for project := range projectsAndTasks {
if listOnlyProjectsAndTasks && !listOnlyTasks { if listOnlyProjectsAndTasks && !listOnlyTasks {
@@ -61,7 +60,7 @@ func printProjects(entries []Entry) {
} }
func listProjectsAndTasks(entries []Entry) (map[string]map[string]bool, []string) { func listProjectsAndTasks(entries []Entry) (map[string]map[string]bool, []string) {
var projectsAndTasks = make(map[string]map[string]bool) projectsAndTasks := make(map[string]map[string]bool)
var allTasks []string var allTasks []string
for _, filteredEntry := range entries { for _, filteredEntry := range entries {
@@ -130,7 +129,6 @@ func trackTask() {
} }
func finishTask(mode int) { func finishTask(mode int) {
user := GetCurrentUser() user := GetCurrentUser()
runningEntryId, err := database.GetRunningEntryId(user) runningEntryId, err := database.GetRunningEntryId(user)
@@ -185,7 +183,6 @@ func finishTask(mode int) {
} }
func finishTaskMetadata(user string, runningEntry *Entry, tmpEntry *Entry) { func finishTaskMetadata(user string, runningEntry *Entry, tmpEntry *Entry) {
if project != "" { if project != "" {
runningEntry.Project = tmpEntry.Project runningEntry.Project = tmpEntry.Project
} }
@@ -207,7 +204,6 @@ func finishTaskMetadata(user string, runningEntry *Entry, tmpEntry *Entry) {
taskGit(&task, runningEntry) taskGit(&task, runningEntry)
} }
} }
func taskGit(task *Task, runningEntry *Entry) { func taskGit(task *Task, runningEntry *Entry) {
+1 -1
View File
@@ -1,8 +1,8 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"os"
// "time" // "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
// "github.com/gookit/color" // "github.com/gookit/color"
+2 -1
View File
@@ -1,8 +1,9 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
+2 -1
View File
@@ -1,8 +1,9 @@
package z package z
import ( import (
"os"
"fmt" "fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
+20 -14
View File
@@ -3,24 +3,30 @@ package z
import ( import (
"fmt" "fmt"
"math" "math"
"github.com/gookit/color" "github.com/gookit/color"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
func GetOutputBoxForNumber(number int, clr (func(...interface {}) string) ) (string) { func GetOutputBoxForNumber(number int, clr func(...interface{}) string) string {
switch(number) { switch number {
case 0: return clr(" ") case 0:
case 1: return clr(" ") return clr(" ")
case 2: return clr("▄▄") case 1:
case 3: return clr("▄") return clr(" ▄")
case 4: return clr("██") case 2:
return clr("▄▄")
case 3:
return clr("▄█")
case 4:
return clr("██")
} }
return clr(" ") return clr(" ")
} }
func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) { func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) []string {
var bar = []string{ bar := []string{
color.FgGray.Render("····"), color.FgGray.Render("····"),
color.FgGray.Render("····"), color.FgGray.Render("····"),
color.FgGray.Render("····"), color.FgGray.Render("····"),
@@ -36,7 +42,7 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) {
divisible := hoursInt - restInt divisible := hoursInt - restInt
fullparts := divisible / 4 fullparts := divisible / 4
colorsFull := make(map[int](func(...interface {}) string)) colorsFull := make(map[int](func(...interface{}) string))
colorsFullIdx := 0 colorsFullIdx := 0
colorFraction := color.FgWhite.Render colorFraction := color.FgWhite.Render
@@ -75,14 +81,14 @@ func GetOutputBarForHours(hours decimal.Decimal, stats []Statistic) ([]string) {
} }
} }
if(restInt > 0) { if restInt > 0 {
bar[(len(bar) - 1 - fullparts)] = " " + GetOutputBoxForNumber(restInt, colorFraction) + " " bar[(len(bar) - 1 - fullparts)] = " " + GetOutputBoxForNumber(restInt, colorFraction) + " "
} }
return bar return bar
} }
func OutputAppendRight(leftStr string, rightStr string, pad int) (string) { func OutputAppendRight(leftStr string, rightStr string, pad int) string {
var output string = "" var output string = ""
var rpos int = 0 var rpos int = 0
@@ -92,7 +98,7 @@ func OutputAppendRight(leftStr string, rightStr string, pad int) (string) {
rightLen := len(right) rightLen := len(right)
for lpos := 0; lpos < leftLen; lpos++ { for lpos := 0; lpos < leftLen; lpos++ {
if left[lpos] == '\n' || lpos == (leftLen - 1) { if left[lpos] == '\n' || lpos == (leftLen-1) {
output = fmt.Sprintf("%s%*s", output, pad, "") output = fmt.Sprintf("%s%*s", output, pad, "")
for rpos = rpos; rpos < rightLen; rpos++ { for rpos = rpos; rpos < rightLen; rpos++ {
output = fmt.Sprintf("%s%c", output, right[rpos]) output = fmt.Sprintf("%s%c", output, right[rpos])
@@ -109,7 +115,7 @@ func OutputAppendRight(leftStr string, rightStr string, pad int) (string) {
return output return output
} }
func GetColorFnFromHex(colorHex string) (func(...interface {}) string) { func GetColorFnFromHex(colorHex string) func(...interface{}) string {
if colorHex == "" { if colorHex == "" {
colorHex = "#dddddd" colorHex = "#dddddd"
} }
+3 -2
View File
@@ -2,10 +2,11 @@ package z
import ( import (
"encoding/json" "encoding/json"
// "fmt"
"os" "os"
"github.com/shopspring/decimal"
"time" "time"
// "fmt"
"github.com/shopspring/decimal"
) )
type TymeEntry struct { type TymeEntry struct {
+2 -2
View File
@@ -9,11 +9,11 @@ import (
var fractional bool var fractional bool
func fmtDuration(dur time.Duration) (string) { func fmtDuration(dur time.Duration) string {
return fmtHours(decimal.NewFromFloat(dur.Hours())) return fmtHours(decimal.NewFromFloat(dur.Hours()))
} }
func fmtHours(hours decimal.Decimal) (string) { func fmtHours(hours decimal.Decimal) string {
if fractional { if fractional {
return hours.StringFixed(2) return hours.StringFixed(2)
} else { } else {
+1 -1
View File
@@ -1,7 +1,7 @@
package main package main
import ( import (
"github.com/mrusme/zeit/z" "github.com/mrusme/zeit/z"
) )
func main() { func main() {