M entries.go => entries.go +1 -1
@@ 81,7 81,7 @@ func (es Entries) Save(f io.Writer) error {
); err != nil {
return err
}
- if i == 0 || !es[i-1].Start.Equal(e.End.Add(time.Second)) {
+ if e.End != zeroTime && (i == 0 || !es[i-1].Start.Equal(e.End.Add(time.Second))) {
if _, err := fmt.Fprintf(f, "-%s", e.End.Format("15:04:05")); err != nil {
return err
}
M go.mod => go.mod +1 -1
@@ 1,4 1,4 @@
-module git.sr.ht/~ghost08/wf
+module git.sr.ht/~ghost08/wt
go 1.16
M main.go => main.go +30 -1
@@ 16,7 16,7 @@ var CLI struct {
Description string `arg required help:"task description"`
} `cmd help:"start a new entry"`
End struct{} `cmd help:"end a running entry"`
- Status struct{} `cmd help:"print the running entry"`
+ Status struct{} `cmd help:"print the running entry" default:"1"`
Report struct {
Month string `arg optional help:"select the month to export in format: YYYYMM (default is the previous month)"`
Output string `optional short:"o" default:"report.xlsx" help:"output file path"`
@@ 146,6 146,35 @@ func end() error {
}
func status() error {
+ es, err := loadEntries()
+ if err != nil {
+ return fmt.Errorf("loading entries: %w", err)
+ }
+ if len(es) == 0 || es[0].End != zeroTime {
+ fmt.Println("no running entries")
+ } else {
+ last := &es[0]
+ fmt.Printf(
+ "%s\t%s\nstart: %s\tduration: %s\n",
+ last.Project,
+ last.Description,
+ last.Start.Format("15:04:05"),
+ time.Now().Sub(last.Start),
+ )
+ }
+ var thisMonthWorked time.Duration
+ y, m, _ := time.Now().Date()
+ for _, e := range es {
+ if ey, em, _ := e.Date.Date(); ey != y || em != m {
+ break
+ }
+ end := e.End
+ if end == zeroTime {
+ end = time.Now()
+ }
+ thisMonthWorked += end.Sub(e.Start)
+ }
+ fmt.Printf("this month:\t%s\n", thisMonthWorked)
return nil
}
M parser.go => parser.go +3 -3
@@ 61,7 61,7 @@ func parseDay(s *scanner) (Entries, error) {
if dateItem.typ != itemDate {
return nil, fmt.Errorf("Expected date item")
}
- d, err := time.Parse("2006-01-02", dateItem.val)
+ d, err := time.ParseInLocation("2006-01-02", dateItem.val, time.Local)
if err != nil {
return nil, fmt.Errorf("Error parsing date at %s: %w", s.l.posString(), err)
}
@@ 97,7 97,7 @@ func parseDay(s *scanner) (Entries, error) {
return nil, fmt.Errorf("expected time item at %s", s.l.posString())
}
var err error
- e.Start, err = time.Parse("2006-01-02 15:04:05", dateItem.val+" "+i.val)
+ e.Start, err = time.ParseInLocation("2006-01-02 15:04:05", dateItem.val+" "+i.val, time.Local)
if err != nil {
return nil, fmt.Errorf("error parsing start time at %s: %w", s.l.posString(), err)
}
@@ 114,7 114,7 @@ func parseDay(s *scanner) (Entries, error) {
continue
}
if i.typ == itemTime {
- e.End, err = time.Parse("2006-01-02 15:04:05", dateItem.val+" "+i.val)
+ e.End, err = time.ParseInLocation("2006-01-02 15:04:05", dateItem.val+" "+i.val, time.Local)
if err != nil {
return nil, fmt.Errorf("error parsing end time at %s: %w", s.l.posString(), err)
}