diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-12-28 18:09:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-28 10:09:57 +0000 |
commit | e743570f65b533552337d9606ac1d906ec054127 (patch) | |
tree | 55042505c0618b567e7f30e7334ec6d66db86230 /models | |
parent | f3999888c0b765380003f814f9c3d5cf80128167 (diff) | |
download | gitea-e743570f65b533552337d9606ac1d906ec054127.tar.gz gitea-e743570f65b533552337d9606ac1d906ec054127.zip |
Refactor timeutil package (#28623)
1. make names more readable
2. remove unused FormatLong/FormatShort
3. use `FormatDate` instead of `Format "2006-01-02"`
Diffstat (limited to 'models')
-rw-r--r-- | models/activities/user_heatmap_test.go | 4 | ||||
-rw-r--r-- | models/asymkey/gpg_key_verify.go | 5 | ||||
-rw-r--r-- | models/issues/comment.go | 6 | ||||
-rw-r--r-- | models/issues/milestone.go | 2 |
4 files changed, 9 insertions, 8 deletions
diff --git a/models/activities/user_heatmap_test.go b/models/activities/user_heatmap_test.go index 657f0f043c..b7babcbde1 100644 --- a/models/activities/user_heatmap_test.go +++ b/models/activities/user_heatmap_test.go @@ -59,8 +59,8 @@ func TestGetUserHeatmapDataByUser(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) // Mock time - timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)) - defer timeutil.Unset() + timeutil.MockSet(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)) + defer timeutil.MockUnset() for _, tc := range testCases { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: tc.userID}) diff --git a/models/asymkey/gpg_key_verify.go b/models/asymkey/gpg_key_verify.go index be36482c74..98a3e7d390 100644 --- a/models/asymkey/gpg_key_verify.go +++ b/models/asymkey/gpg_key_verify.go @@ -107,8 +107,9 @@ func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature st // VerificationToken returns token for the user that will be valid in minutes (time) func VerificationToken(user *user_model.User, minutes int) string { return base.EncodeSha256( - time.Now().Truncate(1*time.Minute).Add(time.Duration(minutes)*time.Minute).Format(time.RFC1123Z) + ":" + - user.CreatedUnix.FormatLong() + ":" + + time.Now().Truncate(1*time.Minute).Add(time.Duration(minutes)*time.Minute).Format( + time.RFC1123Z) + ":" + + user.CreatedUnix.Format(time.RFC1123Z) + ":" + user.Name + ":" + user.Email + ":" + strconv.FormatInt(user.ID, 10)) diff --git a/models/issues/comment.go b/models/issues/comment.go index ba5aed9c65..d92e49a444 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -899,15 +899,15 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is // newDeadline = 0 means deleting if newDeadlineUnix == 0 { commentType = CommentTypeRemovedDeadline - content = issue.DeadlineUnix.Format("2006-01-02") + content = issue.DeadlineUnix.FormatDate() } else if issue.DeadlineUnix == 0 { // Check if the new date was added or modified // If the actual deadline is 0 => deadline added commentType = CommentTypeAddedDeadline - content = newDeadlineUnix.Format("2006-01-02") + content = newDeadlineUnix.FormatDate() } else { // Otherwise modified commentType = CommentTypeModifiedDeadline - content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02") + content = newDeadlineUnix.FormatDate() + "|" + issue.DeadlineUnix.FormatDate() } if err := issue.LoadRepo(ctx); err != nil { diff --git a/models/issues/milestone.go b/models/issues/milestone.go index eb42df8263..f663d42fe9 100644 --- a/models/issues/milestone.go +++ b/models/issues/milestone.go @@ -86,7 +86,7 @@ func (m *Milestone) AfterLoad() { return } - m.DeadlineString = m.DeadlineUnix.Format("2006-01-02") + m.DeadlineString = m.DeadlineUnix.FormatDate() if m.IsClosed { m.IsOverdue = m.ClosedDateUnix >= m.DeadlineUnix } else { |