aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_stopwatch.go
diff options
context:
space:
mode:
authorRené Schaar <rene@schaar.priv.at>2022-02-15 17:50:10 +0100
committerGitHub <noreply@github.com>2022-02-16 00:50:10 +0800
commit609c91665e5e4d6da50af0b2168d6cb46f9d6273 (patch)
tree974e777fbd7262162c4f3b237f3688178962e89c /models/issue_stopwatch.go
parent2be49dee71af997ed944c177a090aeb3e6d606e8 (diff)
downloadgitea-609c91665e5e4d6da50af0b2168d6cb46f9d6273.tar.gz
gitea-609c91665e5e4d6da50af0b2168d6cb46f9d6273.zip
Fix display time of milestones (#18753)
* Fix display time of milestones * Move the SecToTime function From the models/issue_stopwatch.go file to the modules/util package * Rename the sec_to_time file * Updated formatting * Include copyright notice in sec_to_time.go * Apply PR review suggestions - Update copyright notice dates to 2022 - Change `1 day 3h 5min 7s` to `1d 3h 5m 7s` * Rename hrs var and combine conditions * Update unit tests to match new time pattern Changed `1min` to `1m` Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r--models/issue_stopwatch.go34
1 files changed, 3 insertions, 31 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go
index 530a524218..3be9ad4e3f 100644
--- a/models/issue_stopwatch.go
+++ b/models/issue_stopwatch.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
)
// ErrIssueStopwatchNotExist represents an error that stopwatch is not exist
@@ -53,7 +54,7 @@ func (s Stopwatch) Seconds() int64 {
// Duration returns a human-readable duration string based on local server time
func (s Stopwatch) Duration() string {
- return SecToTime(s.Seconds())
+ return util.SecToTime(s.Seconds())
}
func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
@@ -164,7 +165,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
Doer: user,
Issue: issue,
Repo: issue.Repo,
- Content: SecToTime(timediff),
+ Content: util.SecToTime(timediff),
Type: CommentTypeStopTracking,
TimeID: tt.ID,
}); err != nil {
@@ -263,32 +264,3 @@ func cancelStopwatch(ctx context.Context, user *user_model.User, issue *Issue) e
}
return nil
}
-
-// SecToTime converts an amount of seconds to a human-readable string (example: 66s -> 1min 6s)
-func SecToTime(duration int64) string {
- seconds := duration % 60
- minutes := (duration / (60)) % 60
- hours := duration / (60 * 60)
-
- var hrs string
-
- if hours > 0 {
- hrs = fmt.Sprintf("%dh", hours)
- }
- if minutes > 0 {
- if hours == 0 {
- hrs = fmt.Sprintf("%dmin", minutes)
- } else {
- hrs = fmt.Sprintf("%s %dmin", hrs, minutes)
- }
- }
- if seconds > 0 {
- if hours == 0 && minutes == 0 {
- hrs = fmt.Sprintf("%ds", seconds)
- } else {
- hrs = fmt.Sprintf("%s %ds", hrs, seconds)
- }
- }
-
- return hrs
-}