diff --git a/routers/repo/issue_timetrack.go b/routers/repo/issue_timetrack.go index e01cd48a66a7f..ed7d3d1697ee1 100644 --- a/routers/repo/issue_timetrack.go +++ b/routers/repo/issue_timetrack.go @@ -6,6 +6,7 @@ package repo import ( "net/http" + "strconv" "time" "code.gitea.io/gitea/models" @@ -33,7 +34,19 @@ func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) { return } - total := time.Duration(form.Hours)*time.Hour + time.Duration(form.Minutes)*time.Minute + h, err := parseTimeTrackingWithDuration(form.Hours, "h") + if err != nil { + c.Handle(http.StatusInternalServerError, "parseTimeTrackingWithDuration", err) + return + } + + m, err := parseTimeTrackingWithDuration(form.Minutes, "m") + if err != nil { + c.Handle(http.StatusInternalServerError, "parseTimeTrackingWithDuration", err) + return + } + + total := h + m if total <= 0 { c.Flash.Error(c.Tr("repo.issues.add_time_sum_to_small")) @@ -41,10 +54,14 @@ func AddTimeManually(c *context.Context, form auth.AddTimeManuallyForm) { return } - if _, err := models.AddTime(c.User, issue, int64(total)); err != nil { + if _, err := models.AddTime(c.User, issue, int64(total.Seconds())); err != nil { c.Handle(http.StatusInternalServerError, "AddTime", err) return } c.Redirect(url, http.StatusSeeOther) } + +func parseTimeTrackingWithDuration(value int, space string) (time.Duration, error) { + return time.ParseDuration(strconv.Itoa(value) + space) +}