Skip to content

Commit

Permalink
time spent input now properly handles worklog without whitespace
Browse files Browse the repository at this point in the history
For example - `1h30m`
  • Loading branch information
jzyinq committed Jul 18, 2021
1 parent 3352e3c commit 82e55d3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.2] - 2021-05-04
### Fixed
- time spent input now properly handles lack of whitespace between time parts - `1h30m`

## [0.2.1] - 2021-05-04
### Fixed
- `gojira worklogs` now properly reports overall time spent after editing work log
Expand Down
2 changes: 1 addition & 1 deletion gojira/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func PromptForTimeSpent(promptLabel string) (string, error) {
return "", err
}

return result, nil
return FormatTimeSpent(TimeSpentToSeconds(result)), nil
}

func PromptForIssueSelection(issues []Issue) (Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion gojira/tempo.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func GetWorkLogs() []WorkLog {
}

func TimeSpentToSeconds(timeSpent string) int {
r, _ := regexp.Compile("(([0-9]+)h)?(([0-9]+)m)?")
r, _ := regexp.Compile("(([0-9]+)h)?\\s?(([0-9]+)m)?")
match := r.FindStringSubmatch(timeSpent)
var timeSpentSeconds int = 0

Expand Down
3 changes: 3 additions & 0 deletions gojira/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func FormatTimeSpent(timeSpentSeconds int) string {
timeSpent = fmt.Sprintf("%vh", intPart)
}
if floatPart > 0 {
if (intPart) > 0 {
timeSpent += " "
}
timeSpent = timeSpent + fmt.Sprintf("%vm", math.Round(floatPart*60))
}
return timeSpent
Expand Down
22 changes: 20 additions & 2 deletions gojira/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestFormatTimeSpent(t *testing.T) {
{3600, "1h"},
{60, "1m"},
{900, "15m"},
{7080, "1h58m"},
{7080, "1h 58m"},
{901, "15m"},
{959, "16m"},
}
Expand All @@ -33,7 +33,7 @@ func TestCalculateTimeSpent(t *testing.T) {
{TimeSpentSeconds: 901}, // 15m
{TimeSpentSeconds: 959}, // 16m
}
expectedTimeSpent := "3h32m"
expectedTimeSpent := "3h 32m"

actualTimeSpent := CalculateTimeSpent(fixture)

Expand All @@ -60,3 +60,21 @@ func TestFindIssueKeyInString(t *testing.T) {
}

}

func TestTimeSpentToSeconds(t *testing.T) {
fixtures := []struct {
TimeSpent string
expectedTimeSpentInSeconds int
}{
{"1h 30m", 5400},
{"1h30m", 5400},
{"29m", 1740},
}

for _, fixture := range fixtures {
timeSpentInSeconds := TimeSpentToSeconds(fixture.TimeSpent)
if timeSpentInSeconds != fixture.expectedTimeSpentInSeconds {
t.Errorf("Incorrect timeSpent - got %d instead of %d", timeSpentInSeconds, fixture.expectedTimeSpentInSeconds)
}
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
Calling without arguments will try to detect issue from git branch,
otherwise it will display list of last updated issues you're are assigned to.`,
Version: "0.2.1",
Version: "0.2.2",
Before: func(context *cli.Context) error {
if context.Args().First() != "config" {
// dont' check envs on ConfigCommand
Expand Down

0 comments on commit 82e55d3

Please sign in to comment.