zeit/z/stats.go

55 lines
1.2 KiB
Go
Raw Normal View History

2020-10-16 15:36:44 +00:00
package z
import (
"os"
"fmt"
"time"
2020-10-16 15:36:44 +00:00
"github.com/spf13/cobra"
// "github.com/shopspring/decimal"
// "github.com/gookit/color"
2020-10-16 15:36:44 +00:00
)
var statsCmd = &cobra.Command{
Use: "stats",
Short: "Display activity statistics",
Long: "Display statistics on all tracked activities.",
Run: func(cmd *cobra.Command, args []string) {
user := GetCurrentUser()
2020-10-16 15:36:44 +00:00
entries, err := database.ListEntries(user)
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
2020-10-16 15:36:44 +00:00
cal, _ := NewCalendar(entries)
2020-10-16 15:36:44 +00:00
today := time.Now()
month, weeknumber := GetISOWeekInMonth(today)
month0 := month - 1
weeknumber0 := weeknumber - 1
thisWeek := cal.GetOutputForWeekCalendar(today, month0, weeknumber0)
2020-10-16 15:36:44 +00:00
oneWeekAgo := today.AddDate(0, 0, -7)
month, weeknumber = GetISOWeekInMonth(oneWeekAgo)
month0 = month - 1
weeknumber0 = weeknumber - 1
previousWeek := cal.GetOutputForWeekCalendar(oneWeekAgo, month0, weeknumber0)
2020-10-16 15:36:44 +00:00
fmt.Printf("%s\n", OutputAppendRight(thisWeek, previousWeek, 16))
2020-10-16 15:36:44 +00:00
return
},
}
func init() {
rootCmd.AddCommand(statsCmd)
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}