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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 18 additions & 17 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 14 additions & 14 deletions
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

Lines changed: 3 additions & 3 deletions
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,

0 commit comments

Comments
 (0)