Skip to content

Commit 85202d4

Browse files
authored
Display ui time with customize time location (#7792)
* display ui time with customize time location * fix lint * rename UILocation to DefaultUILocation * move time related functions to modules/timeutil * fix tests * fix tests * fix build * fix swagger
1 parent 5a44be6 commit 85202d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+770
-662
lines changed

custom/conf/app.ini.sample

+3
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ MAX_FILES = 5
547547
; Special supported values are ANSIC, UnixDate, RubyDate, RFC822, RFC822Z, RFC850, RFC1123, RFC1123Z, RFC3339, RFC3339Nano, Kitchen, Stamp, StampMilli, StampMicro and StampNano
548548
; For more information about the format see http://golang.org/pkg/time/#pkg-constants
549549
FORMAT =
550+
; Location the UI time display i.e. Asia/Shanghai
551+
; Empty means server's location setting
552+
DEFAULT_UI_LOCATION =
550553

551554
[log]
552555
ROOT_PATH =

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,12 @@ Two special environment variables are passed to the render command:
503503
- `GITEA_PREFIX_SRC`, which contains the current URL prefix in the `src` path tree. To be used as prefix for links.
504504
- `GITEA_PREFIX_RAW`, which contains the current URL prefix in the `raw` path tree. To be used as prefix for image paths.
505505

506+
## Time (`time`)
507+
- `FORMAT`: Time format to diplay on UI. i.e. RFC1123 or 2006-01-02 15:04:05
508+
- `DEFAULT_UI_LOCATION`: Default location of time on the UI, so that we can display correct user's time on UI. i.e. Shanghai/Asia
509+
506510
## Other (`other`)
507511

508512
- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.
509513
- `SHOW_FOOTER_VERSION`: **true**: Show Gitea version information in the footer.
510-
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.
514+
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.

docs/content/doc/advanced/config-cheat-sheet.zh-cn.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ IS_INPUT_FILE = false
237237
- RENDER_COMMAND: 工具的命令行命令及参数。
238238
- IS_INPUT_FILE: 输入方式是最后一个参数为文件路径还是从标准输入读取。
239239

240-
240+
## Time (`time`)
241+
- `FORMAT`: 显示在界面上的时间格式。比如: RFC1123 或者 2006-01-02 15:04:05
242+
- `DEFAULT_UI_LOCATION`: 默认显示在界面上的时区,默认为本地时区。比如: Asia/Shanghai
241243

242244
## Other (`other`)
243245

models/action.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"code.gitea.io/gitea/modules/log"
2121
"code.gitea.io/gitea/modules/setting"
2222
api "code.gitea.io/gitea/modules/structs"
23-
"code.gitea.io/gitea/modules/util"
23+
"code.gitea.io/gitea/modules/timeutil"
2424

2525
"github.com/Unknwon/com"
2626
"xorm.io/builder"
@@ -91,9 +91,9 @@ type Action struct {
9191
Comment *Comment `xorm:"-"`
9292
IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"`
9393
RefName string
94-
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
95-
Content string `xorm:"TEXT"`
96-
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
94+
IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
95+
Content string `xorm:"TEXT"`
96+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
9797
}
9898

9999
// GetOpType gets the ActionType of this action.

models/admin.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"os"
1010

1111
"code.gitea.io/gitea/modules/log"
12-
"code.gitea.io/gitea/modules/util"
12+
"code.gitea.io/gitea/modules/timeutil"
1313

1414
"github.com/Unknwon/com"
1515
)
@@ -26,8 +26,8 @@ const (
2626
type Notice struct {
2727
ID int64 `xorm:"pk autoincr"`
2828
Type NoticeType
29-
Description string `xorm:"TEXT"`
30-
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
29+
Description string `xorm:"TEXT"`
30+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
3131
}
3232

3333
// TrStr returns a translation format string.

models/attachment.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"code.gitea.io/gitea/modules/setting"
1414
api "code.gitea.io/gitea/modules/structs"
15-
"code.gitea.io/gitea/modules/util"
15+
"code.gitea.io/gitea/modules/timeutil"
1616

1717
"github.com/go-xorm/xorm"
1818
gouuid "github.com/satori/go.uuid"
@@ -27,9 +27,9 @@ type Attachment struct {
2727
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
2828
CommentID int64
2929
Name string
30-
DownloadCount int64 `xorm:"DEFAULT 0"`
31-
Size int64 `xorm:"DEFAULT 0"`
32-
CreatedUnix util.TimeStamp `xorm:"created"`
30+
DownloadCount int64 `xorm:"DEFAULT 0"`
31+
Size int64 `xorm:"DEFAULT 0"`
32+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
3333
}
3434

3535
// IncreaseDownloadCount is update download count + 1

models/branches.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/modules/base"
1212
"code.gitea.io/gitea/modules/log"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/timeutil"
1415
"code.gitea.io/gitea/modules/util"
1516

1617
"github.com/Unknwon/com"
@@ -30,16 +31,16 @@ type ProtectedBranch struct {
3031
BranchName string `xorm:"UNIQUE(s)"`
3132
CanPush bool `xorm:"NOT NULL DEFAULT false"`
3233
EnableWhitelist bool
33-
WhitelistUserIDs []int64 `xorm:"JSON TEXT"`
34-
WhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
35-
EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"`
36-
MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
37-
MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
38-
ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
39-
ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
40-
RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"`
41-
CreatedUnix util.TimeStamp `xorm:"created"`
42-
UpdatedUnix util.TimeStamp `xorm:"updated"`
34+
WhitelistUserIDs []int64 `xorm:"JSON TEXT"`
35+
WhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
36+
EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"`
37+
MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
38+
MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
39+
ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"`
40+
ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
41+
RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"`
42+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
43+
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
4344
}
4445

4546
// IsProtected returns if the branch is protected
@@ -374,13 +375,13 @@ func (repo *Repository) DeleteProtectedBranch(id int64) (err error) {
374375

375376
// DeletedBranch struct
376377
type DeletedBranch struct {
377-
ID int64 `xorm:"pk autoincr"`
378-
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
379-
Name string `xorm:"UNIQUE(s) NOT NULL"`
380-
Commit string `xorm:"UNIQUE(s) NOT NULL"`
381-
DeletedByID int64 `xorm:"INDEX"`
382-
DeletedBy *User `xorm:"-"`
383-
DeletedUnix util.TimeStamp `xorm:"INDEX created"`
378+
ID int64 `xorm:"pk autoincr"`
379+
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
380+
Name string `xorm:"UNIQUE(s) NOT NULL"`
381+
Commit string `xorm:"UNIQUE(s) NOT NULL"`
382+
DeletedByID int64 `xorm:"INDEX"`
383+
DeletedBy *User `xorm:"-"`
384+
DeletedUnix timeutil.TimeStamp `xorm:"INDEX created"`
384385
}
385386

386387
// AddDeletedBranch adds a deleted branch to the database

models/commit_status.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/modules/setting"
1515
api "code.gitea.io/gitea/modules/structs"
16-
"code.gitea.io/gitea/modules/util"
16+
"code.gitea.io/gitea/modules/timeutil"
1717

1818
"github.com/go-xorm/xorm"
1919
)
@@ -66,8 +66,8 @@ type CommitStatus struct {
6666
Creator *User `xorm:"-"`
6767
CreatorID int64
6868

69-
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
70-
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
69+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
70+
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
7171
}
7272

7373
func (status *CommitStatus) loadRepo(e Engine) (err error) {

models/gpg_key.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
"code.gitea.io/gitea/modules/git"
1919
"code.gitea.io/gitea/modules/log"
20-
"code.gitea.io/gitea/modules/util"
20+
"code.gitea.io/gitea/modules/timeutil"
2121

2222
"github.com/go-xorm/xorm"
2323
"github.com/keybase/go-crypto/openpgp"
@@ -27,14 +27,14 @@ import (
2727

2828
// GPGKey represents a GPG key.
2929
type GPGKey struct {
30-
ID int64 `xorm:"pk autoincr"`
31-
OwnerID int64 `xorm:"INDEX NOT NULL"`
32-
KeyID string `xorm:"INDEX CHAR(16) NOT NULL"`
33-
PrimaryKeyID string `xorm:"CHAR(16)"`
34-
Content string `xorm:"TEXT NOT NULL"`
35-
CreatedUnix util.TimeStamp `xorm:"created"`
36-
ExpiredUnix util.TimeStamp
37-
AddedUnix util.TimeStamp
30+
ID int64 `xorm:"pk autoincr"`
31+
OwnerID int64 `xorm:"INDEX NOT NULL"`
32+
KeyID string `xorm:"INDEX CHAR(16) NOT NULL"`
33+
PrimaryKeyID string `xorm:"CHAR(16)"`
34+
Content string `xorm:"TEXT NOT NULL"`
35+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
36+
ExpiredUnix timeutil.TimeStamp
37+
AddedUnix timeutil.TimeStamp
3838
SubsKey []*GPGKey `xorm:"-"`
3939
Emails []*EmailAddress
4040
CanSign bool
@@ -51,7 +51,7 @@ type GPGKeyImport struct {
5151

5252
// BeforeInsert will be invoked by XORM before inserting a record
5353
func (key *GPGKey) BeforeInsert() {
54-
key.AddedUnix = util.TimeStampNow()
54+
key.AddedUnix = timeutil.TimeStampNow()
5555
}
5656

5757
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
@@ -223,8 +223,8 @@ func parseSubGPGKey(ownerID int64, primaryID string, pubkey *packet.PublicKey, e
223223
KeyID: pubkey.KeyIdString(),
224224
PrimaryKeyID: primaryID,
225225
Content: content,
226-
CreatedUnix: util.TimeStamp(pubkey.CreationTime.Unix()),
227-
ExpiredUnix: util.TimeStamp(expiry.Unix()),
226+
CreatedUnix: timeutil.TimeStamp(pubkey.CreationTime.Unix()),
227+
ExpiredUnix: timeutil.TimeStamp(expiry.Unix()),
228228
CanSign: pubkey.CanSign(),
229229
CanEncryptComms: pubkey.PubKeyAlgo.CanEncrypt(),
230230
CanEncryptStorage: pubkey.PubKeyAlgo.CanEncrypt(),
@@ -301,8 +301,8 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
301301
KeyID: pubkey.KeyIdString(),
302302
PrimaryKeyID: "",
303303
Content: content,
304-
CreatedUnix: util.TimeStamp(pubkey.CreationTime.Unix()),
305-
ExpiredUnix: util.TimeStamp(expiry.Unix()),
304+
CreatedUnix: timeutil.TimeStamp(pubkey.CreationTime.Unix()),
305+
ExpiredUnix: timeutil.TimeStamp(expiry.Unix()),
306306
Emails: emails,
307307
SubsKey: subkeys,
308308
CanSign: pubkey.CanSign(),

models/gpg_key_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99
"time"
1010

11-
"code.gitea.io/gitea/modules/util"
11+
"code.gitea.io/gitea/modules/timeutil"
1212

1313
"github.com/stretchr/testify/assert"
1414
)
@@ -112,7 +112,7 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
112112
key := &GPGKey{
113113
KeyID: pubkey.KeyIdString(),
114114
Content: content,
115-
CreatedUnix: util.TimeStamp(pubkey.CreationTime.Unix()),
115+
CreatedUnix: timeutil.TimeStamp(pubkey.CreationTime.Unix()),
116116
CanSign: pubkey.CanSign(),
117117
CanEncryptComms: pubkey.PubKeyAlgo.CanEncrypt(),
118118
CanEncryptStorage: pubkey.PubKeyAlgo.CanEncrypt(),
@@ -122,7 +122,7 @@ MkM/fdpyc2hY7Dl/+qFmN5MG5yGmMpQcX+RNNR222ibNC1D3wg==
122122
cannotsignkey := &GPGKey{
123123
KeyID: pubkey.KeyIdString(),
124124
Content: content,
125-
CreatedUnix: util.TimeStamp(pubkey.CreationTime.Unix()),
125+
CreatedUnix: timeutil.TimeStamp(pubkey.CreationTime.Unix()),
126126
CanSign: false,
127127
CanEncryptComms: false,
128128
CanEncryptStorage: false,

models/issue.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/setting"
1818
api "code.gitea.io/gitea/modules/structs"
19+
"code.gitea.io/gitea/modules/timeutil"
1920
"code.gitea.io/gitea/modules/util"
2021

2122
"github.com/Unknwon/com"
@@ -49,11 +50,11 @@ type Issue struct {
4950
NumComments int
5051
Ref string
5152

52-
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
53+
DeadlineUnix timeutil.TimeStamp `xorm:"INDEX"`
5354

54-
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
55-
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
56-
ClosedUnix util.TimeStamp `xorm:"INDEX"`
55+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
56+
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
57+
ClosedUnix timeutil.TimeStamp `xorm:"INDEX"`
5758

5859
Attachments []*Attachment `xorm:"-"`
5960
Comments []*Comment `xorm:"-"`
@@ -90,7 +91,7 @@ func (issue *Issue) loadTotalTimes(e Engine) (err error) {
9091

9192
// IsOverdue checks if the issue is overdue
9293
func (issue *Issue) IsOverdue() bool {
93-
return util.TimeStampNow() >= issue.DeadlineUnix
94+
return timeutil.TimeStampNow() >= issue.DeadlineUnix
9495
}
9596

9697
// LoadRepo loads issue's repository
@@ -744,7 +745,7 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (er
744745

745746
issue.IsClosed = isClosed
746747
if isClosed {
747-
issue.ClosedUnix = util.TimeStampNow()
748+
issue.ClosedUnix = timeutil.TimeStampNow()
748749
} else {
749750
issue.ClosedUnix = 0
750751
}
@@ -991,7 +992,7 @@ func (issue *Issue) GetTasksDone() int {
991992
}
992993

993994
// GetLastEventTimestamp returns the last user visible event timestamp, either the creation of this issue or the close.
994-
func (issue *Issue) GetLastEventTimestamp() util.TimeStamp {
995+
func (issue *Issue) GetLastEventTimestamp() timeutil.TimeStamp {
995996
if issue.IsClosed {
996997
return issue.ClosedUnix
997998
}
@@ -1794,7 +1795,7 @@ func UpdateIssue(issue *Issue) error {
17941795
}
17951796

17961797
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
1797-
func UpdateIssueDeadline(issue *Issue, deadlineUnix util.TimeStamp, doer *User) (err error) {
1798+
func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *User) (err error) {
17981799

17991800
// if the deadline hasn't changed do nothing
18001801
if issue.DeadlineUnix == deadlineUnix {

models/issue_comment.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ import (
1212
"strings"
1313

1414
"code.gitea.io/gitea/modules/git"
15+
"code.gitea.io/gitea/modules/log"
16+
"code.gitea.io/gitea/modules/markup"
1517
"code.gitea.io/gitea/modules/markup/markdown"
1618
"code.gitea.io/gitea/modules/setting"
19+
api "code.gitea.io/gitea/modules/structs"
20+
"code.gitea.io/gitea/modules/timeutil"
21+
1722
"github.com/Unknwon/com"
1823
"github.com/go-xorm/xorm"
1924
"xorm.io/builder"
20-
21-
api "code.gitea.io/gitea/modules/structs"
22-
23-
"code.gitea.io/gitea/modules/log"
24-
"code.gitea.io/gitea/modules/markup"
25-
"code.gitea.io/gitea/modules/util"
2625
)
2726

2827
// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
@@ -130,8 +129,8 @@ type Comment struct {
130129
// Path represents the 4 lines of code cemented by this comment
131130
Patch string `xorm:"TEXT"`
132131

133-
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
134-
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
132+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
133+
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
135134

136135
// Reference issue in commit message
137136
CommitSHA string `xorm:"VARCHAR(40)"`
@@ -711,7 +710,7 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue
711710
})
712711
}
713712

714-
func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix util.TimeStamp) (*Comment, error) {
713+
func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) {
715714

716715
var content string
717716
var commentType CommentType

models/issue_dependency.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ package models
77
import (
88
"code.gitea.io/gitea/modules/log"
99
"code.gitea.io/gitea/modules/setting"
10-
"code.gitea.io/gitea/modules/util"
10+
"code.gitea.io/gitea/modules/timeutil"
1111
)
1212

1313
// IssueDependency represents an issue dependency
1414
type IssueDependency struct {
15-
ID int64 `xorm:"pk autoincr"`
16-
UserID int64 `xorm:"NOT NULL"`
17-
IssueID int64 `xorm:"UNIQUE(issue_dependency) NOT NULL"`
18-
DependencyID int64 `xorm:"UNIQUE(issue_dependency) NOT NULL"`
19-
CreatedUnix util.TimeStamp `xorm:"created"`
20-
UpdatedUnix util.TimeStamp `xorm:"updated"`
15+
ID int64 `xorm:"pk autoincr"`
16+
UserID int64 `xorm:"NOT NULL"`
17+
IssueID int64 `xorm:"UNIQUE(issue_dependency) NOT NULL"`
18+
DependencyID int64 `xorm:"UNIQUE(issue_dependency) NOT NULL"`
19+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
20+
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
2121
}
2222

2323
// DependencyType Defines Dependency Type Constants

0 commit comments

Comments
 (0)