summaryrefslogtreecommitdiffstats
path: root/models/issues
diff options
context:
space:
mode:
author6543 <m.huber@kithara.com>2023-06-23 14:12:39 +0200
committerGitHub <noreply@github.com>2023-06-23 12:12:39 +0000
commitb0215c40cdf9a3e46a45a3823b894998d1044cda (patch)
tree564ac8316c1cee99437879ba8594cbe786d04283 /models/issues
parenta954c93a68072042aa7dad717b6fa002c83a58fb (diff)
downloadgitea-b0215c40cdf9a3e46a45a3823b894998d1044cda.tar.gz
gitea-b0215c40cdf9a3e46a45a3823b894998d1044cda.zip
Store and use seconds for timeline time comments (#25392)
this will allow us to fully localize it later PS: we can not migrate back as the old value was a one-way conversion prepare for #25213 --- *Sponsored by Kithara Software GmbH*
Diffstat (limited to 'models/issues')
-rw-r--r--models/issues/tracked_time.go31
-rw-r--r--models/issues/tracked_time_test.go2
2 files changed, 20 insertions, 13 deletions
diff --git a/models/issues/tracked_time.go b/models/issues/tracked_time.go
index 698014afeb..1d7592926b 100644
--- a/models/issues/tracked_time.go
+++ b/models/issues/tracked_time.go
@@ -6,6 +6,7 @@ package issues
import (
"context"
"errors"
+ "fmt"
"time"
"code.gitea.io/gitea/models/db"
@@ -173,10 +174,12 @@ func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Tim
}
if _, err := CreateComment(ctx, &CreateCommentOptions{
- Issue: issue,
- Repo: issue.Repo,
- Doer: user,
- Content: util.SecToTime(amount),
+ Issue: issue,
+ Repo: issue.Repo,
+ Doer: user,
+ // Content before v1.21 did store the formated string instead of seconds,
+ // so use "|" as delimeter to mark the new format
+ Content: fmt.Sprintf("|%d", amount),
Type: CommentTypeAddTimeManual,
TimeID: t.ID,
}); err != nil {
@@ -251,10 +254,12 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
return err
}
if _, err := CreateComment(ctx, &CreateCommentOptions{
- Issue: issue,
- Repo: issue.Repo,
- Doer: user,
- Content: "- " + util.SecToTime(removedTime),
+ Issue: issue,
+ Repo: issue.Repo,
+ Doer: user,
+ // Content before v1.21 did store the formated string instead of seconds,
+ // so use "|" as delimeter to mark the new format
+ Content: fmt.Sprintf("|%d", removedTime),
Type: CommentTypeDeleteTimeManual,
}); err != nil {
return err
@@ -280,10 +285,12 @@ func DeleteTime(t *TrackedTime) error {
}
if _, err := CreateComment(ctx, &CreateCommentOptions{
- Issue: t.Issue,
- Repo: t.Issue.Repo,
- Doer: t.User,
- Content: "- " + util.SecToTime(t.Time),
+ Issue: t.Issue,
+ Repo: t.Issue.Repo,
+ Doer: t.User,
+ // Content before v1.21 did store the formated string instead of seconds,
+ // so use "|" as delimeter to mark the new format
+ Content: fmt.Sprintf("|%d", t.Time),
Type: CommentTypeDeleteTimeManual,
}); err != nil {
return err
diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go
index baa170b201..37ba1cfdc4 100644
--- a/models/issues/tracked_time_test.go
+++ b/models/issues/tracked_time_test.go
@@ -35,7 +35,7 @@ func TestAddTime(t *testing.T) {
assert.Equal(t, int64(3661), tt.Time)
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddTimeManual, PosterID: 3, IssueID: 1})
- assert.Equal(t, "1 hour 1 minute", comment.Content)
+ assert.Equal(t, "|3661", comment.Content)
}
func TestGetTrackedTimes(t *testing.T) {