Refactor SecToTime() function (#18863)
- Add helper method to reduce redundancy - Expand the scope from displaying days to years - Reduce irrelevance by not displaying small units (hours, minutes, seconds) when bigger ones apply (years)
This commit is contained in:
parent
b75ad7b87f
commit
6859b69198
3 changed files with 64 additions and 40 deletions
|
@ -34,7 +34,7 @@ func TestAddTime(t *testing.T) {
|
|||
assert.Equal(t, int64(3661), tt.Time)
|
||||
|
||||
comment := unittest.AssertExistsAndLoadBean(t, &Comment{Type: CommentTypeAddTimeManual, PosterID: 3, IssueID: 1}).(*Comment)
|
||||
assert.Equal(t, comment.Content, "1h 1m 1s")
|
||||
assert.Equal(t, comment.Content, "1 hour 1 minute")
|
||||
}
|
||||
|
||||
func TestGetTrackedTimes(t *testing.T) {
|
||||
|
@ -86,7 +86,7 @@ func TestTotalTimes(t *testing.T) {
|
|||
assert.Len(t, total, 1)
|
||||
for user, time := range total {
|
||||
assert.Equal(t, int64(1), user.ID)
|
||||
assert.Equal(t, "6m 40s", time)
|
||||
assert.Equal(t, "6 minutes 40 seconds", time)
|
||||
}
|
||||
|
||||
total, err = TotalTimes(&FindTrackedTimesOptions{IssueID: 2})
|
||||
|
@ -94,9 +94,9 @@ func TestTotalTimes(t *testing.T) {
|
|||
assert.Len(t, total, 2)
|
||||
for user, time := range total {
|
||||
if user.ID == 2 {
|
||||
assert.Equal(t, "1h 1m 2s", time)
|
||||
assert.Equal(t, "1 hour 1 minute", time)
|
||||
} else if user.ID == 1 {
|
||||
assert.Equal(t, "20s", time)
|
||||
assert.Equal(t, "20 seconds", time)
|
||||
} else {
|
||||
assert.Error(t, assert.AnError)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ func TestTotalTimes(t *testing.T) {
|
|||
assert.Len(t, total, 1)
|
||||
for user, time := range total {
|
||||
assert.Equal(t, int64(2), user.ID)
|
||||
assert.Equal(t, "1s", time)
|
||||
assert.Equal(t, "1 second", time)
|
||||
}
|
||||
|
||||
total, err = TotalTimes(&FindTrackedTimesOptions{IssueID: 4})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue