Skip to content

Commit

Permalink
Add days to run duration
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Dec 8, 2023
1 parent ecaf82c commit b63fdac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app/pc_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ func isStringDefined(str string) bool {

func durationToString(dur time.Duration) string {
if dur.Minutes() < 3 {
//seconds
return dur.Round(time.Second).String()
} else if dur.Minutes() < 60 {
//minutes
return fmt.Sprintf("%.0fm", dur.Minutes())
} else if dur.Hours() < 24 {
//hours and minutes
return fmt.Sprintf("%dh%dm", int(dur.Hours()), int(dur.Minutes())%60)
} else if dur.Hours() < 48 {
//days and hours
return fmt.Sprintf("%dd%dh", int(dur.Hours())/24, int(dur.Hours())%24)
} else {
return fmt.Sprintf("%dh", int(dur.Hours()))
//days
return fmt.Sprintf("%dd", int(dur.Hours())/24)
}
}
9 changes: 8 additions & 1 deletion src/app/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ func TestDurationToString(t *testing.T) {
args: args{
dur: 25*time.Hour + 50*time.Minute,
},
want: "25h",
want: "1d1h",
},
{
name: "above 48h",
args: args{
dur: 49*time.Hour + 50*time.Minute,
},
want: "2d",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit b63fdac

Please sign in to comment.