Skip to content

Commit

Permalink
Allow to specify month and year
Browse files Browse the repository at this point in the history
  • Loading branch information
EgZvor committed Dec 9, 2022
1 parent f24e7a1 commit 5e2340c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
}

if len(os.Args) < 2 {
pterm.Println(pterm.Yellow("Usage: tlog <time> <task> [day] [comment]"))
pterm.Println(pterm.Yellow("Usage: tlog <time> <task> [date|day] [comment]"))
return
}

Expand Down Expand Up @@ -137,7 +137,15 @@ func convertToDay(input string) (time.Time, error) {
return time.Date(y, m, d, 0, 0, 0, 0, time.UTC), nil
}

return time.Time{}, fmt.Errorf("day of the week, or day number expected")
if t, err := time.Parse("01.02", input); err == nil {
return time.Date(time.Now().Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.UTC), nil
}

if t, err := time.Parse("2006.01.02", input); err == nil {
return t, nil
}

return time.Time{}, fmt.Errorf("[yy.]mm.dd, day of the week, or day of the month expected")
}

func convertToTimeLog(inputTime string) (time.Duration, error) {
Expand Down
2 changes: 2 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func Test_convertToDay(t *testing.T) {
{name: "friday", input: "friday", want: time.Now().Add(daysDiff(time.Friday, time.Now().Weekday()))},
{name: "saturday", input: "saturday", want: time.Now().Add(daysDiff(time.Saturday, time.Now().Weekday()))},
{name: "sunday", input: "sunday", want: time.Now().Add(daysDiff(time.Weekday(7), time.Now().Weekday()))},
{name: "mm.dd", input: "04.20", want: time.Date(time.Now().Year(), time.April, 20, 0, 0, 0, 0, time.UTC)},
{name: "yyyy.mm.dd", input: "1999.04.20", want: time.Date(1999, time.April, 20, 0, 0, 0, 0, time.UTC)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
15 changes: 8 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ Simple CLI that helps log time on JIRA issues.

## Usage
```bash
log 1h SCENTRE-5912 # log 1 hour into SCENTRE-5912 for today
log 1 5814 # log 1 hour into {{DefaultProject}}-5814
log 30m review # log 30 minutes into task aliased "review"
log 1h review yesterday # log 1 hour yesterday
log 1h review monday # log 1 hour review for monday for current week
log 1h review mon # log 1 hour review for monday for current week
log 1h review 22 # log 1 hour review for 22nd if current month
log 1h SCENTRE-5912 # log 1 hour into SCENTRE-5912 for today
log 1 5814 # log 1 hour into {{DefaultProject}}-5814
log 30m review # log 30 minutes into task aliased "review"
log 1h review yesterday # log 1 hour yesterday
log 1h review monday # log 1 hour review for monday for current week
log 1h review mon # log 1 hour review for monday for current week
log 1h review 22 # log 1 hour review for 22nd if current month
log 1h review 2022.12.31 # log 1 hour review for 31st of December, 2022
```

## Install
Expand Down

0 comments on commit 5e2340c

Please sign in to comment.