Skip to content

Commit cce9d48

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Various Mermaid improvements (go-gitea#18776) [skip ci] Updated translations via Crowdin Fix display time of milestones (go-gitea#18753)
2 parents 9b30dbb + 616146f commit cce9d48

File tree

17 files changed

+134
-91
lines changed

17 files changed

+134
-91
lines changed

models/issue_stopwatch.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models/db"
1313
user_model "code.gitea.io/gitea/models/user"
1414
"code.gitea.io/gitea/modules/timeutil"
15+
"code.gitea.io/gitea/modules/util"
1516
)
1617

1718
// ErrIssueStopwatchNotExist represents an error that stopwatch is not exist
@@ -53,7 +54,7 @@ func (s Stopwatch) Seconds() int64 {
5354

5455
// Duration returns a human-readable duration string based on local server time
5556
func (s Stopwatch) Duration() string {
56-
return SecToTime(s.Seconds())
57+
return util.SecToTime(s.Seconds())
5758
}
5859

5960
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
164165
Doer: user,
165166
Issue: issue,
166167
Repo: issue.Repo,
167-
Content: SecToTime(timediff),
168+
Content: util.SecToTime(timediff),
168169
Type: CommentTypeStopTracking,
169170
TimeID: tt.ID,
170171
}); err != nil {
@@ -263,32 +264,3 @@ func cancelStopwatch(ctx context.Context, user *user_model.User, issue *Issue) e
263264
}
264265
return nil
265266
}
266-
267-
// SecToTime converts an amount of seconds to a human-readable string (example: 66s -> 1min 6s)
268-
func SecToTime(duration int64) string {
269-
seconds := duration % 60
270-
minutes := (duration / (60)) % 60
271-
hours := duration / (60 * 60)
272-
273-
var hrs string
274-
275-
if hours > 0 {
276-
hrs = fmt.Sprintf("%dh", hours)
277-
}
278-
if minutes > 0 {
279-
if hours == 0 {
280-
hrs = fmt.Sprintf("%dmin", minutes)
281-
} else {
282-
hrs = fmt.Sprintf("%s %dmin", hrs, minutes)
283-
}
284-
}
285-
if seconds > 0 {
286-
if hours == 0 && minutes == 0 {
287-
hrs = fmt.Sprintf("%ds", seconds)
288-
} else {
289-
hrs = fmt.Sprintf("%s %ds", hrs, seconds)
290-
}
291-
}
292-
293-
return hrs
294-
}

models/issue_tracked_time.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212
user_model "code.gitea.io/gitea/models/user"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/util"
1415

1516
"xorm.io/builder"
1617
)
@@ -177,7 +178,7 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim
177178
Issue: issue,
178179
Repo: issue.Repo,
179180
Doer: user,
180-
Content: SecToTime(amount),
181+
Content: util.SecToTime(amount),
181182
Type: CommentTypeAddTimeManual,
182183
TimeID: t.ID,
183184
}); err != nil {
@@ -226,7 +227,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string,
226227
}
227228
return nil, err
228229
}
229-
totalTimes[user] = SecToTime(total)
230+
totalTimes[user] = util.SecToTime(total)
230231
}
231232
return totalTimes, nil
232233
}
@@ -260,7 +261,7 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
260261
Issue: issue,
261262
Repo: issue.Repo,
262263
Doer: user,
263-
Content: "- " + SecToTime(removedTime),
264+
Content: "- " + util.SecToTime(removedTime),
264265
Type: CommentTypeDeleteTimeManual,
265266
}); err != nil {
266267
return err
@@ -289,7 +290,7 @@ func DeleteTime(t *TrackedTime) error {
289290
Issue: t.Issue,
290291
Repo: t.Issue.Repo,
291292
Doer: t.User,
292-
Content: "- " + SecToTime(t.Time),
293+
Content: "- " + util.SecToTime(t.Time),
293294
Type: CommentTypeDeleteTimeManual,
294295
}); err != nil {
295296
return err

models/issue_tracked_time_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAddTime(t *testing.T) {
3434
assert.Equal(t, int64(3661), tt.Time)
3535

3636
comment := unittest.AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddTimeManual, PosterID: 3, IssueID: 1}).(*Comment)
37-
assert.Equal(t, comment.Content, "1h 1min 1s")
37+
assert.Equal(t, comment.Content, "1h 1m 1s")
3838
}
3939

4040
func TestGetTrackedTimes(t *testing.T) {
@@ -86,15 +86,15 @@ func TestTotalTimes(t *testing.T) {
8686
assert.Len(t, total, 1)
8787
for user, time := range total {
8888
assert.Equal(t, int64(1), user.ID)
89-
assert.Equal(t, "6min 40s", time)
89+
assert.Equal(t, "6m 40s", time)
9090
}
9191

9292
total, err = TotalTimes(&FindTrackedTimesOptions{IssueID: 2})
9393
assert.NoError(t, err)
9494
assert.Len(t, total, 2)
9595
for user, time := range total {
9696
if user.ID == 2 {
97-
assert.Equal(t, "1h 1min 2s", time)
97+
assert.Equal(t, "1h 1m 2s", time)
9898
} else if user.ID == 1 {
9999
assert.Equal(t, "20s", time)
100100
} else {

modules/templates/helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func NewFuncMap() []template.FuncMap {
256256
},
257257
"Printf": fmt.Sprintf,
258258
"Escape": Escape,
259-
"Sec2Time": models.SecToTime,
259+
"Sec2Time": util.SecToTime,
260260
"ParseDeadline": func(deadline string) []string {
261261
return strings.Split(deadline, "|")
262262
},
@@ -447,7 +447,7 @@ func NewTextFuncMap() []texttmpl.FuncMap {
447447
},
448448
"Printf": fmt.Sprintf,
449449
"Escape": Escape,
450-
"Sec2Time": models.SecToTime,
450+
"Sec2Time": util.SecToTime,
451451
"ParseDeadline": func(deadline string) []string {
452452
return strings.Split(deadline, "|")
453453
},

modules/util/sec_to_time.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2022 Gitea. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package util
6+
7+
import "fmt"
8+
9+
// SecToTime converts an amount of seconds to a human-readable string (example: 66s -> 1min 6s)
10+
func SecToTime(duration int64) string {
11+
seconds := duration % 60
12+
minutes := (duration / (60)) % 60
13+
hours := duration / (60 * 60) % 24
14+
days := duration / (60 * 60) / 24
15+
16+
var formattedTime string
17+
18+
if days > 0 {
19+
formattedTime = fmt.Sprintf("%dd", days)
20+
}
21+
if hours > 0 {
22+
if formattedTime == "" {
23+
formattedTime = fmt.Sprintf("%dh", hours)
24+
} else {
25+
formattedTime = fmt.Sprintf("%s %dh", formattedTime, hours)
26+
}
27+
}
28+
if minutes > 0 {
29+
if formattedTime == "" {
30+
formattedTime = fmt.Sprintf("%dm", minutes)
31+
} else {
32+
formattedTime = fmt.Sprintf("%s %dm", formattedTime, minutes)
33+
}
34+
}
35+
if seconds > 0 {
36+
if formattedTime == "" {
37+
formattedTime = fmt.Sprintf("%ds", seconds)
38+
} else {
39+
formattedTime = fmt.Sprintf("%s %ds", formattedTime, seconds)
40+
}
41+
}
42+
43+
return formattedTime
44+
}

modules/util/sec_to_time_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2022 Gitea. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package util
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestSecToTime(t *testing.T) {
14+
assert.Equal(t, SecToTime(10), "10s")
15+
assert.Equal(t, SecToTime(100), "1m 40s")
16+
assert.Equal(t, SecToTime(1000), "16m 40s")
17+
assert.Equal(t, SecToTime(10000), "2h 46m 40s")
18+
assert.Equal(t, SecToTime(100000), "1d 3h 46m 40s")
19+
assert.Equal(t, SecToTime(1000000), "11d 13h 46m 40s")
20+
}

options/locale/locale_zh-TW.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,9 +2581,13 @@ auths.filter=使用者篩選器
25812581
auths.admin_filter=管理者篩選器
25822582
auths.restricted_filter=受限制的篩選器
25832583
auths.restricted_filter_helper=留白則不限制任何使用者。使用米字「*」將所有不符合管理員篩選條件的使用者設定為受限。
2584+
auths.verify_group_membership=驗證 LDAP 群組成員資格(篩選器留空以跳過)
25842585
auths.group_search_base=群組搜尋的 Base DN
25852586
auths.group_attribute_list_users=包含使用者清單的群組屬性
25862587
auths.user_attribute_in_group=群組中列出的使用者屬性
2588+
auths.map_group_to_team=對應 LDAP 群組到組織團隊(欄位留空以跳過)
2589+
auths.map_group_to_team_removal=如果使用者不屬於相對應的 LDAP 群組,將使用者從已同步的團隊移除。
2590+
auths.enable_ldap_groups=啟用 LDAP 群組
25872591
auths.ms_ad_sa=MS AD 搜尋屬性
25882592
auths.smtp_auth=SMTP 驗證類型
25892593
auths.smtphost=SMTP 主機地址
@@ -2816,6 +2820,7 @@ monitor.queue.type=類型
28162820
monitor.queue.exemplar=型別
28172821
monitor.queue.numberworkers=工作者數量
28182822
monitor.queue.maxnumberworkers=最大工作者數量
2823+
monitor.queue.numberinqueue=佇列中的數量
28192824
monitor.queue.review=檢視組態
28202825
monitor.queue.review_add=檢視/新增工作者
28212826
monitor.queue.configuration=初始組態

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"less": "4.1.2",
2424
"less-loader": "10.2.0",
2525
"license-checker-webpack-plugin": "0.2.1",
26-
"mermaid": "8.13.10",
26+
"mermaid": "8.14.0",
2727
"mini-css-extract-plugin": "2.5.3",
2828
"monaco-editor": "0.32.1",
2929
"monaco-editor-webpack-plugin": "7.0.1",

routers/web/repo/issue_timetrack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"code.gitea.io/gitea/models"
1212
"code.gitea.io/gitea/modules/context"
13+
"code.gitea.io/gitea/modules/util"
1314
"code.gitea.io/gitea/modules/web"
1415
"code.gitea.io/gitea/services/forms"
1516
)
@@ -81,6 +82,6 @@ func DeleteTime(c *context.Context) {
8182
return
8283
}
8384

84-
c.Flash.Success(c.Tr("repo.issues.del_time_history", models.SecToTime(t.Time)))
85+
c.Flash.Success(c.Tr("repo.issues.del_time_history", util.SecToTime(t.Time)))
8586
c.Redirect(issue.HTMLURL())
8687
}

0 commit comments

Comments
 (0)